not in带来的问题

在使用not in 的时候,内表和外表比较的字段如果含有null的话会出现查询逻辑错误的问题,如:
select count(1) from "customer_tmp" t where t."name" not in (select "name" from "client1")

如果name的值为null的话,用not in会有逻辑错误!

结论:还是全部换成not exists吧,语法如下:
select count(1) from "customer_tmp" t where not exists (select c."name" from "client1" c where c."name"=t."name")

你可能感兴趣的:(数据库)