• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Join query problem

#1
[eluser]andriu[/eluser]
Hi guys

I would like to start of to thank the users on this forum!!
And also say that I find CI amazing.

I'm pretty new to mysql and just discovered the power of "join"!!

Now i'm facing a problem

Ive got three tables

Code:
incidents
elevators
clients

a incident is connected either to a client or a elevator
a elevator is always connected to a client

I try to join them like this:

Code:
$this->db->from('incidencias');
$this->db->join('elevators', 'incidents_elevator_id = elevator_id', 'LEFT');
$this->db->join('clients', 'incidents_client_id = client_id', 'LEFT');

In an incident I either save the elevator_id or the client_id depending on the type of incident.
(I know start to think that this was an error)

And now i want to be able to select the "elevator" or "client" depending on the incidencia
but if it is related to the elevator I also want to select the client.

With the code above I just get either the client or the elevator.

Is what im trying to do impossible with my table structure?

My old way of doing it is running another query for every incident!!

(a eleveator could change owner along the way and I would then want to select the new client)

Thanks in advance for any help!


Messages In This Thread
Join query problem - by El Forum - 02-25-2010, 07:59 AM
Join query problem - by El Forum - 02-25-2010, 08:38 AM
Join query problem - by El Forum - 02-25-2010, 08:48 AM
Join query problem - by El Forum - 02-25-2010, 08:49 AM
Join query problem - by El Forum - 02-25-2010, 09:04 AM
Join query problem - by El Forum - 02-25-2010, 09:30 AM
Join query problem - by El Forum - 02-25-2010, 10:00 AM
Join query problem - by El Forum - 02-25-2010, 10:05 AM
Join query problem - by El Forum - 03-03-2010, 06:00 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.