我在查询时遇到的一个问题
select * from table where p_flag is null and p_flag = 'Y'
我需要查询出p_flag为空和为'Y'的记录,但是这样查询出来的记录没有,这是为什么?
select * from table where p_flag is null and p_flag = 'Y'
我需要查询出p_flag为空和为'Y'的记录,但是这样查询出来的记录没有,这是为什么?
and是交集 or是并集
and是并集交集
or才是与或集select * from table where p_flag is null or p_flag = 'Y'
p_flag is null and p_flag = 'Y' p_flag既然取空,再p_flag='Y'岂不矛盾了
where p_flag is null and p_flag = 'Y' 中,说明p_flag要同时满足:
1. p_flag is null
2. p_flag = 'Y'
即p_flag必须为空,同时p_flag必须等于Y,这两个条件本身是相互矛盾的,因此不会有任何记录同时满足这两个条件,故而查出来的结果是空的。