这里是我的查询子查询返回NULL “NOT IN”
select distinct(Challan_No)
from Challan_tb
where Challan_No not in
(
select Challan_No from Invoice_tb where Customer_ID =2 and InvYear=2013
) and InvYear=2013 and Customer_ID =2
子查询返回NULL
所以外部查询不工作
请帮
这里是我的查询子查询返回NULL “NOT IN”
select distinct(Challan_No)
from Challan_tb
where Challan_No not in
(
select Challan_No from Invoice_tb where Customer_ID =2 and InvYear=2013
) and InvYear=2013 and Customer_ID =2
子查询返回NULL
所以外部查询不工作
请帮
有一个简单的,明显的修复,如果你不想改变查询的结构太多:
select distinct(Challan_No)
from Challan_tb
where Challan_No not in
(
select Challan_No from Invoice_tb where Customer_ID =2 and InvYear=2013
and Challan_No is not null --This line is new
) and InvYear=2013 and Customer_ID =2
你可以尝试一个LEFT JOIN代替。我认为Access会更好地消化这个。
select distinct(Challan_tb.Challan_No)
from Challan_tb
left join Invoice_tb on Invoice_tb.Challan_No = Challan_tb.Challan_No
where Challan_tb.InvYear=2013 and Challan_tb.Customer_ID=2
and Invoice_tb.InvYear is null --or any other Invoice_tb field
您忘记了'AND Invoice_tb.Customer_ID = 2和Invoice_tb.InvYear = 2013'(它应该在'ON'子句中。) –
我假定Challan_No是连接两者的唯一标识符,在ON子句中呈现Customer_ID和InvYear不必要,但仍在WHERE子句中使用。 – Matt
所以,你想获得不同Challan_No那里有没有发票?尝试给你的子查询一个别名。 '从Invoice_tb中选择Challan_No I,其中I.Customer_ID = 2和I.InvYear = 2013' –