我想从主表中选择指定的列,该列不存在于链接表中。但即使id
仍然不存在于链接表中,它也会给我一个空行。
SELECT faculty_mt.firstName FROM faculty_mt
INNER JOIN section_settings_lt ON section_settings_lt.adviser_id = faculty_mt.faculty_id
WHERE faculty_mt.faculty_id NOT IN (SELECT adviser_id FROM section_settings_lt);
我尝试从SELECT adviser_id
更改为SELECT session_id
,但这为我提供了一个存在于我的链接表中的值。
faculty_mt
faculty_id | firstName
15 Daisy
16 Orange
section_settings_lt
section_id | adviser_id | session_id
1 15 1
输出应为:
firstName
Orange
答案 0 :(得分:1)
你可以试试这个:
SELECT
faculty_mt.firstName
FROM
faculty_mt
LEFT JOIN
section_settings_lt
ON
section_settings_lt.adviser_id = faculty_mt.faculty_id
WHERE
section_settings_lt.adviser_id is NULL;