I have a query to bring up records for a job log of IT work performed for a specified client. Part of the information I would like the query to gather is the name of office the work is associated with. In the joblog table itself the office is refereed to by and ID number which is the PK of another table, clientlocations. On some job entries in the joblog table, the ID number for the office is specified by a 0, denoting that the work performed was remote support. When attempting to look up the associated office name from clientlocations with PK 0, the whole resulting row is dropped because there is no PK entry of value 0 in the clientlocations table.
The following query pulls up all of the information I need EXCEPT for the office name as specified in the clientlocations table.
SELECT joblog.joblogJobID,
joblog.joblogPerformedOn,
joblog.joblogWorkDescription,
joblog.joblogTime,
joblog.joblogTravelCost,
joblog.joblogLaborCost,
joblog.joblogJobTotal,
joblog.joblogOfficeID,
billingclasses.billingclassesType,
users.userName
FROM joblog, billingclasses, users
WHERE joblog.joblogClientID=5 AND billingclasses.billingclassesID=joblog.joblogBillingClass AND
users.userID=joblog.joblogEngineerID
I modified the query with a LEFT JOIN:
SELECT joblog.joblogJobID,
joblog.joblogPerformedOn,
joblog.joblogWorkDescription,
joblog.joblogTime,
joblog.joblogTravelCost,
joblog.joblogLaborCost,
joblog.joblogJobTotal,
joblog.joblogOfficeID,
billingclasses.billingclassesType,
users.userName
FROM joblog, billingclasses, users
WHERE joblog.joblogClientID=5 AND billingclasses.billingclassesID=joblog.joblogBillingClass AND
users.userID=joblog.joblogEngineerID
LEFT JOIN clientlocations ON
clientlocations.clientlocationsOfficeID=joblog.joblogOfficeID
and I receive the following error message:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN clientlocations ON clientlocations.clientlocationsOfficeID=joblog.jobl' at line 1
Can't figure out what I am doing wrong, it seemed simple enough...
Any help? Thanks!