在基本JOIN查询中无效使用Null

时间:2016-08-10 16:39:23

标签: sql ms-access null

我正在尝试在Access中运行以下查询:

SELECT CompareByOrderAndDescr.BOrder
FROM CompareByOrderAndDescr
LEFT JOIN OrdersNotReceived ON CompareByOrderAndDescr.BOrder = OrdersNotReceived.BOrder
WHERE OrdersNotReceived.BOrder Is Null

然而,我得到了"无效使用Null"错误信息。

我有两个已保存的查询,名为" CompareByOrderAndDescr"和" OrdersNotReceived"。在任何一个查询" BOrder"中都没有Null值。领域。我一直在寻找错误的原因,但似乎没有一个适用于此。

我认为这是从一个表中查找不在另一个表中的记录的基本SQL。我错过了什么?

编辑:为了澄清,以下两个查询都返回0行:

SELECT * FROM CompareByOrderAndDescr
WHERE BOrder IS NULL

SELECT * FROM OrdersNotReceived
WHERE BOrder IS NULL

另外,对于它的价值,这里是我开始时的原始查询,然后将OrdersNotReceived查询保存为自己的东西,试图将问题分解成更小的部分:

SELECT BOrder
FROM CompareByOrderAndDescr cb
LEFT JOIN (
    SELECT BOrder
    FROM CompareByOrderAndDescr
    WHERE [Received]='Not Received') nr ON nr.BOrder=cb.BOrder

2 个答案:

答案 0 :(得分:0)

我正在阅读您的问题的方式,您希望来自CompareByOrderAndDescr的BOrders不在OrdersNotReceived中。在这种情况下,我会使用NOT IN子句:

SELECT CompareByOrderAndDescr.BOrder
FROM CompareByOrderAndDescr
WHERE CompareByOrderAndDescr.BOrder NOT IN
(SELECT OrdersNotReceived.BOrder
FROM OrdersNotReceived)

答案 1 :(得分:0)

请检查CompareByOrderAndDescr.BOrder和OrdersNotReceived.BOrder列是否都允许空值?