将两个除外条款合并为一个结果集

时间:2019-05-31 20:16:32

标签: sql sql-server tsql

是否可以将两个Except子句合并为一个结果集?

这行不通,但是本质上是我想要实现的目标

SELECT * FROM dbo.TemptblSHAREVendors EXCEPT SELECT * FROM dbo.tblSHAREVendors
UNION
SELECT * FROM dbo.tblSHAREVendors EXCEPT SELECT * FROM dbo.TemptblSHAREVendors

1 个答案:

答案 0 :(得分:2)

您可以使用括号强制执行操作的优先级。

(SELECT *
        FROM dbo.TemptblSHAREVendors
 EXCEPT
 SELECT *
        FROM dbo.tblSHAREVendors)
UNION
(SELECT *
        FROM dbo.tblSHAREVendors
 EXCEPT
 SELECT *
        FROM dbo.TemptblSHAREVendors);