1. 程式人生 > >sql 中 not in 或者 not exists 查不出資料

sql 中 not in 或者 not exists 查不出資料

可能原因:B表中存在NULL值

例子:

1、查不出資料

not in

select name from a where name not in (select distinct name from b ) 

 not exists 

select name from a where  not exists (select distinct name from b  ) 

2、更改後查出資料

not in

select name from a where name not in (select distinct name from b  where name is not null) 

 not exists 

select name from a where  not exists (select distinct name from b  where name is not null)