簡體   English   中英

如何僅從右表中檢索沒有匹配記錄的左表值

[英]How to retrieve only left table values no matching records from right table

我有兩個表,我將表 1 數據與表 2 數據相匹配。 我如何從左表中獲取數據而從右表中沒有匹配的記錄意味着如果在右表中找到任何匹配項,我需要省略它,結果是剩余的值

嘗試使用左連接進行下面的查詢,並且 righttable.id 的給定條件為空 - 這會給你不匹配的行

select * from lefttable left join righttable on lefttable.id=righttable.id
    where righttable.id is null
SELECT *
FROM L_TABLE L
LEFT JOIN R_TABLE R 
 ON L.id=R.id
WHERE R.id IS NULL
SELECT table1.column1, table2.column2...
FROM table1
LEFT JOIN table2
ON table1.common_field = table2.common_field;

在 where 條件下使用左連接與右表列

    select t1.* from table1 t1 left join table2 t2 on t1.id=t2.id
   where t2.id is null

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM