SQL查询帮助-仅选择不存在的行

SQL查询帮助-仅选择不存在的行,sql,sql-server,Sql,Sql Server,我知道之前有人问过这个问题,但我就是不能让它按我需要的方式工作 我在两个不同的模式中有两个相同的表。让我们把它们称为表1和表2。表1是主表,它包含所有条目。。。表2应该有重复的数据,但缺少一些行。我需要能够从表1中仅选择表2中缺少的行,我尝试了以下方法 select order, item from table1 where status = 133 and not exists (select order, item from table2 where status = 133) 但它总是

我知道之前有人问过这个问题,但我就是不能让它按我需要的方式工作

我在两个不同的模式中有两个相同的表。让我们把它们称为表1和表2。表1是主表,它包含所有条目。。。表2应该有重复的数据,但缺少一些行。我需要能够从表1中仅选择表2中缺少的行,我尝试了以下方法

select order, item from table1 where status = 133 and not exists 
(select order, item from table2 where status = 133)
但它总是不返回任何结果。我猜我只是把语法弄错了,但想不出正确的方法


有什么帮助吗?

您做得不对,以下是您应该如何做:

select order, item from table1 where status = 133 and not exists 
(select order, item from table2 where status = 133 and order = table1.order
and item=table1.item)
或者,另一个选项(未测试):

(select order, item from table1 where status = 133)
except
(select order, item from table2 where status = 133)