我有两个JOIN查询,它们提供Id
的输出列。如何查找查询1返回但查询2未返回的所有Id
值?
select Id from Table1 join Table2;
select Id from Table2 join Table3;
答案 0 :(得分:6)
SELECT id FROM dbo.Table1 INNER JOIN dbo.Table2 ON ...
EXCEPT
SELECT id FROM dbo.Table2 INNER JOIN dbo.Table3 ON ...;
答案 1 :(得分:0)
试试这个:
select Id from Table1 join Table2
union
select Id from Table2 join Table3