【发布时间】:2023-03-21 23:44:01
【问题描述】:
这是我的查询:
Select a.* from Table1 a, Table2 b
Where
a.tid=b.tid and
b.createddate=(Select max(createddate) from Table2) and
a.tid not in (Select distinct tid from Table3);
问题是我知道这应该返回一些有效的输出,但它没有。如果我将 Select distinct tid from Table3 替换为硬编码值,例如 ('T001','T002' ,'T003','T004') 然后它工作正常并返回数据。
怎么了?我错过了什么吗?请帮忙。
【问题讨论】:
-
:手动运行查询
Select distinct tid from Table3,如果该查询返回任何记录为null,则not in 将不返回任何结果 -
另外,删除 distinct,它对性能没有帮助。
-
Gaurav 查询返回数据。 RedFilter- 谢谢我已经删除了不同的。
-
@Ram: 如果 tid 不是主键,你能否将 NOT IN 查询重写为
NOT IN (Select tid from Table3 where tid is not null)以确认