here is the query:
[ SELECT l.id AS link_id, l.title, l.link, l.time_submitted, i.code AS code1, p.code AS code2
FROM tbl_link l
LEFT OUTER JOIN tbl_code1 i
ON l.submitter_id = i.user_id
AND l.id = i.tbl_code2
LEFT OUTER JOIN tbl_code2 p
ON l.submitter_id = p.user_id
AND l.id = p.link_id
I am trying to get everything from tbl_link and also colums whether or not there is an entry in tbl_code1 and tbl_code2
Your code looks correct for what you have described. I am guessing that your JOIN conditions (the ON) aren't right if you aren't getting the right data back.
Post some sample data and expected result if you need more help.
1 Like
Just a guess, but if you have any WHERE condition(s) on the i and/or p table, you must move those into the LEFT JOIN rather than using WHERE. Putting LEFT JOIN table conditions in the WHERE effectively turns it into an INNER JOIN.