简体   繁体   中英

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM