sql查询未被外键关联的数据

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql查询未被外键关联的数据相关的知识,希望对你有一定的参考价值。

主表附表用的是外键。怎么样查询未被关联的数据呢?
比如
aa表 bb表
aid bid
bid age
name

如何查询bb表中未被aa表关联的数据呢?

参考技术A select * from bb b where not exists (select 1 from aa a where a.bid=b.bid)本回答被提问者和网友采纳 参考技术B select a.aid,a.name,b.bid,b.age from aa a join bb b on (a.bid=b.bid); 参考技术C 你的问题表述不清楚啊!根据理解,试着解答一下吧:
select aa.name bb.age from aa inner join bb on aa.bid=bb.bid

以上是关于sql查询未被外键关联的数据的主要内容,如果未能解决你的问题,请参考以下文章