I'm having a problem inner joining multiple tables. When I join any of the three tables it returns the results correctly. For instance:
SELECT jobLink.*
, trucks.*
, employees.*
FROM jobLink
JOIN schedule
ON jobLink.jobID = schedule.id
JOIN employees
ON jobLink.empID = employees.id
WHERE jobLink.thedate = '2014-18-07'
AND schedule.id = 439
Will return the jobname and all the employees on the job under it.
As soon as I join the last join I get an empty result leading me to believe that my order is off or something. I'm open to other suggestions as there is possibly a better or more efficient way to accomplish this so I'm listing my tables below. Any help is appreciated.
jobLink table:
id | jobID | empID | copy | truck | thedate
_____________________________________________________________________
employees table:
id | name | abb | pos | current
_____________________________________________________________________
trucks table:
id | num | sort
_____________________________________________________________________
schedule table:
id | name | address | city | phone | email
_____________________________________________________________________
My query is currently:
SELECT jobLink.*
, trucks.*
, employees.*
FROM jobLink
JOIN schedule
ON jobLink.jobID = schedule.id
JOIN employees
ON jobLink.empID = employees.id
JOIN trucks
ON jobLink.truck = trucks.id
WHERE jobLink.thedate = '2014-18-07'
AND schedule.id = 439
Each table has a different quantity of results. Schedule has 1 result but the rest will vary depending on how many employees and trucks are on the job (from the schedule). Im trying to produce something like this:
the employees wont end up under the trucks because i dont have that set up in the db tables but can be listed before or after the employee list. Thanks in advance!
yes, the output is php sorry for not being more specific... @Strawberry after speaking to a colleague of mine, his suggestion is to change the structure. By changing the structure and adding a job_truck
table and a job_employees
table I am able to accomplish what I need by using inner joins. @RubahMalam yes i did try left joins but i am unable to accomplish it in one query. Thank you for the suggestions.