I’ve been working on a project at work and I need data from two tables. I’m no expert on MySQL queries, but I got this far:
SELECT *
FROM `p_list` AS pl
JOIN `employee` AS em
WHERE em.id =10
AND pl.employee_id =10
It works fine when there is a pl.employee_id, but returns o result where there isn’t. It makes sense, but I don’t know how i can get it to return where em.id=10 and if pl.employee_id is set.
I’m about to give up and just run two queries and let PHP do the dirty work.
Try this, use
LEFT JOINBasically, what you are doing now is an
INNER JOIN.INNER JOINis different fromLEFT JOIN(which is what you need).INNER JOINonly returns result if a record specified in the join condition has atleast one match on the other table.LEFT JOIN, on the other hand, returns all rows specified on the LEFT table whether it has a match or none match on the other table.