php - MYSQL LEFT JOIN is not working as expected not showing all rows from left table
I have the following structure for form_meta
and entry_meta
I am running this query
SELECT
sequence AS sequence,
meta_label AS label,
results AS results,
entry_id
FROM
`form_meta`
LEFT JOIN
`entry_meta` ON form_meta.id = entry_meta.form_meta_id
WHERE
`form_meta`.`form_id` = 10
AND is_active = 1
But, I am getting 4 rows as result. I am looking for 5 rows as form_meta
is having 5 rows, last row must be empty.
Answer
Solution:
What happens if you use proper table aliases?
SELECT
fm.sequence AS sequence,
fm.meta_label AS label,
em.results AS results,
em.entry_id
FROM form_meta fm
LEFT JOIN entry_meta em ON fm.id = em.form_meta_id
WHERE fm.form_id = 10 AND fm.is_active = 1;
Source