删除联接中不存在的记录 [英] Delete records not present in join
本文介绍了删除联接中不存在的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
想象两个表格(A和B):
Imagine two tables (A and B):
A B
1 2
2 3
6 5
4 7
9 11
13
23
9
现在我要删除A中不存在的记录,例如从A删除1,6和4.
Now I want to delete records from A that are not present in B, e.g deleting 1, 6 and 4 from A.
我最初的想法是,你可以否定连接的结果。
My initial idea is that you could 'negate' the results of a join.
推荐答案
DELETE FROM A WHERE NOT EXISTS (SELECT * FROM B WHERE A.id = B.id)
我假设这些列被命名为 id
。
I've assumed that those columns are named id
.
这篇关于删除联接中不存在的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文