目的是查询A表中存在而B表中不存在的记录,我写了如下代码
select DISTINCT a,b,c,d,e,f,0
from A
where (a not in (select a from B) or
b not in (select b from B) or
c not in (select c from B) or
d not in (select d from B) or
e not in (select e from B) or
f not in (select f from B)) and
(g LIKE '%灰斗加热%' or g LIKE '%瓷套加热%') and
h = '0'
查询结果是,有些应该查出来的没查出来,
原因是:以表A中的记录是
a b c d e f g h
a5,b5,c5,d5,e5,f5,灰斗加热,‘0’
为例, 假设这条记录存在于表A中而不存在于表B中,则此记录应被查出来,但是按照我的代码,当表B中同时存在存在以下两条记录时
a b c d e f g h
a0,b5,c5,d5,e5,f5,灰斗加热,‘0’
a5,b0,c0,d0,e0,f0,灰斗加热,‘0’
表A中这条记录不能被查出来,因为a5,b5,c5,d5,e5,f5这五个条件确实都存在于表B中,只不过是没有存在于同一条记录中。
我知道查询条件不能被割裂开来,但是pgsql子查询中不允许查询多个字段,应该怎么写,请大神指点一下