以下 SQL 语句不起作用:
SELECT stock.IdStock
,stock.Descr
FROM [Inventory].[dbo].[Stock] stock
WHERE stock.IdStock NOT IN
(SELECT foreignStockId FROM
[Subset].[dbo].[Products])
以下 SQL 语句不起作用:
SELECT stock.IdStock
,stock.Descr
FROM [Inventory].[dbo].[Stock] stock
WHERE stock.IdStock NOT IN
(SELECT foreignStockId FROM
[Subset].[dbo].[Products])
可能返回一个NULL
. 尝试
SELECT stock.IdStock
,stock.Descr
FROM [Inventory].[dbo].[Stock] stock
WHERE stock.IdStock NOT IN
(SELECT foreignStockId FROM
[Subset].[dbo].[Products]
WHERE foreignStockId IS NOT NULL )
对于这种类型的查询,我通常使用 NOT EXISTS
SELECT stock.idstock,
stock.descr
FROM [Inventory].[dbo].[Stock] stock
WHERE NOT EXISTS (SELECT *
FROM [Subset].[dbo].[Products] p
WHERE p.foreignstockid = stock.idstock)
最可能
SELECT foreignStockId FROM
[Subset].[dbo].[Products]
查询返回至少一个 NULL 值
尝试存在
SELECT stock.IdStock
,stock.Descr
FROM [Inventory].[dbo].[Stock] stock
WHERE NOT EXISTS
(SELECT * FROM [Subset].[dbo].[Products]
where stock.IdStock =foreignStockId )