SQL 存在A表而不在B表中的数据

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/DeMonliuhui/article/details/88688750

查询

A、B两表使用ID关联,找出ID存在A表,但是不存在B表的数据。

select distinct A.ID from A where A.ID not in (select ID from B)

删除

A、B两表使用ID关联,删除ID存在A表,但是不存在B表的数据。

delete
from A where A.ID not in (select ID from B)

参考

https://www.cnblogs.com/zqifa/p/sql-select-1.html

猜你喜欢

转载自blog.csdn.net/DeMonliuhui/article/details/88688750