[英]how to get unique record from table in mysql
我有兩個表,分別叫abc
和xyz
。 表xyz
包含列id, xyz
包含abc_id
。
我想找到第一個表中存在但第二個表中不存在的記錄。 我怎樣才能做到這一點。
如果要從abc表中獲取記錄,而不是xyz表中的記錄;
SELECT abc_id FROM abc
WHERE abc_id NOT IN (SELECT id from xyz)
Select id from xyz
where id not in ( Select abc_id from abc)
在此處查看有關NOT IN()
比較函數的更多詳細信息
您可以使用IN作為@ m.hasan答案或使用EXISTS
> Select id from xyz where not exists ( Select abc_id from abc where
> abc_id = xyz.id)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.