【发布时间】:2017-05-30 11:31:06
【问题描述】:
【问题讨论】:
-
我相信类似的问题已经存在:Subtract a table from another
【问题讨论】:
您正在寻找一个左排除连接
SELECT A.*
FROM Table_A A
LEFT JOIN Table_B B
ON A.Key = B.Key
WHERE B.Key IS NULL
请参阅这篇关于 SQL 连接的文章,它会有所帮助
https://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins
【讨论】:
使用not exists:
select l.*
from `left` l
where not exists (select 1 from `right` r where r.id = l.id);
如果需要更多列比较,可以展开逻辑:
select l.*
from `left` l
where not exists (select 1
from `right` r
where r.col1 = l.col1 and
r.col2 = l.col2 and
. . .
);
【讨论】: