如何查找未连接的记录? [英] How do I find records that are not joined?
本文介绍了如何查找未连接的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个连接在一起的表.
I have two tables that are joined together.
A 有很多 B
通常你会这样做:
select * from a,b where b.a_id = a.id
从 a 中获取在 b 中有记录的所有记录.
To get all of the records from a that has a record in b.
如何只获取 a 中没有 b 中任何内容的记录?
How do I get just the records in a that does not have anything in b?
推荐答案
select * from a where id not in (select a_id from b)
或者像这个线程上的其他人说的:
Or like some other people on this thread says:
select a.* from a
left outer join b on a.id = b.a_id
where b.a_id is null
这篇关于如何查找未连接的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文