1

我正在使用 SQL Server 和 SQL CE 我正在尝试制作一个简单的子查询

Select * From Item_Lots where Distribution_Code NOT IN
(select Distribution_Code from Stock_Serials)

,但它不适用于 SQL CE !

有什么解决方法吗?

4

2 回答 2

0

I know this is a bit late, but is Distribution_Code nullable?

I hit the same problem since = cannot do null comparisons in Sql Compact. Filtering out null values from the inner query solved this for me

SELECT * FROM Item_Lots WHERE Distribution_Code NOT IN
(SELECT Distribution_Code FROM Stock_Serials WHERE Distribution_Code IS NOT NULL GROUP BY Distribution_Code)
于 2014-07-10T18:41:04.410 回答
0

我不知道这是否适用于 SQL CE,但它是替换 NOT IN SQL 的标准方法。

SELECT Item_Lots.*
FROM Item_Lots 
    LEFT OUTER JOIN Stock_Serials
        ON Item_Lots.Distribution_Code = Stock_Serials.Distribution_Code 
WHERE Stock_Serials.Distribution_Code IS NULL

你也可以试试这个:

SELECT *
FROM Item_Lots
WHERE NOT EXISTS
(
    SELECT *
    FROM Stock_Serials
    WHERE Stock_Serials.Distribution_Code = Item_Lots.Distribution_Code 
)

参考:我应该使用 NOT IN、OUTER APPLY、LEFT OUTER JOIN、EXCEPT 还是 NOT EXISTS?

于 2013-04-30T10:23:31.617 回答