我有两个名为tmptable1
和tmptable2
的sql数据表
我正在尝试显示 tmptable1
中包含但 tmptable2
中不包含的数据
我编写了以下查询,但它显示空白结果,但我知道 tmptable1
中有一条记录,但 tmptable2
中没有
以下是我的查询。我做错了什么。
select * from tmptable1 where name not in(select name from tmptable2 where status='active')
最佳答案
您还可以利用 EXCEPT and INTERSECT :
下面给出了 tmptable1
中存在但 tmptable2
中不存在的名称:
SELECT name FROM tmptable1
EXCEPT
SELECT name FROM tmptable2
这为您提供了通用名称:
SELECT name FROM tmptable1
INTERSECT
SELECT name FROM tmptable2
关于sql - 查找两个 SQL 数据表之间的不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46803552/