2017-08-08 80 views
0

我想從我的主表中選擇指定列中不存在於我的鏈接表中的列。但它給了我一個空行,即使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_idSELECT 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

回答

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;