获取sql中不在另一个表中的数据
我有这样一个问题:获取sql中不在另一个表中的数据,sql,sql-server,Sql,Sql Server,我有这样一个问题: SELECT t.TBarcode,t.PlateNo from dbo.Transaction_tbl t WHERE Status=0 输出: TBarcode PlateNo -------------------- -------------------- 6191112123456 123456 6191112123457 123458 6191112123459 123459 我还有一个表,如
SELECT t.TBarcode,t.PlateNo
from dbo.Transaction_tbl t
WHERE Status=0
输出:
TBarcode PlateNo
-------------------- --------------------
6191112123456 123456
6191112123457 123458
6191112123459 123459
我还有一个表,如下所示:
TBarcode datetime
-------------------- --------------------
6191112123456 2013-07-19 11:12:25.000
6191112123464 2013-07-19 11:12:25.000
我想获得TBarcode
和PlateNo
中未包含在EmailSendLog\u tbl
中的所有TBarcode
,因此我尝试了如下查询:
SELECT t.TBarcode, t.PlateNo
from dbo.Transaction_tbl t
WHERE Status = 0 and NOT in (SELECT TBarcode FROM dbo.EmailSendLog_tbl)
但这是一个错误:
关键字“in”附近的语法不正确
将最后一行更改为:
WHERE Status=0 and t.TBarcode NOT IN(SELECT TBarcode FROM dbo.EmailSendLog_tbl)
您需要将
t.TBarcode
放在之前,而不是放在中
SELECT t.TBarcode,t.PlateNo
from dbo.Transaction_tbl t
WHERE Status=0 and t.TBarcode NOT in (SELECT TBarcode FROM dbo.EmailSendLog_tbl)
谢谢..先生..这对我来说很好..谢谢你的帮助