我正在尝试基于Oracle 12c从DETAIL表中选择条目,该表应满足两个where约束:
以下带有子选择(语句内)的语句完全不返回结果。
select *
from DETAIL
where (PARENT_ID) in (
select ID from MASTER where COL1 = 1)
and COL2 is null;
左连接也没有返回结果:
select d.*
from MASTER m
left join DETAIL d
on d.PARENT_ID = m.ID
where m.COL1 = 1
and d.COL2 is null;
我的表格设置包含以下表格:
create table MASTER (
ID NUMBER(19) NOT NULL,
COL1 NUMBER(19),
primary key (ID)
);
insert into MASTER ("ID", "COL1") VALUES (1, 1);
insert into MASTER ("ID", "COL1") VALUES (2, 2);
insert into MASTER ("ID", "COL1") VALUES (3, 1);
create table DETAIL (
ID NUMBER(19) NOT NULL,
PARENT_ID NUMBER(19),
COL2 NUMBER(2,0),
primary key (ID),
foreign key (PARENT_ID) references MASTER(ID)
);
insert into DETAIL ("ID", "PARENT_ID", "COL2") VALUES (1, 1, 1);
insert into DETAIL ("ID", "PARENT_ID", "COL2") VALUES (2, 2, 1);
insert into DETAIL ("ID", "PARENT_ID", "COL2") VALUES (3, 3, 1);
insert into DETAIL ("ID", "PARENT_ID", "COL2") VALUES (4, 3, 2);
基于上面的代码,我希望获得的条目超过0个。
有什么要求吗?谢谢!
答案 0 :(得分:1)
在DETAIL表中,COL2始终有一个值,因此永远不会为NULL。因此,永远不会满足COL2 IS NULL
条件,并且您的查询不会返回任何结果。