PostgreSQL查询选择除

时间:2015-08-24 14:08:25

标签: sql postgresql

A

reference, row, count, etc...

B

reference, row, xxx, etc...

如何从表 B 获取 A 引用的所有记录,不包括行行 em>在 B

select "reference", "row", "count", "xxx" 
from B 
where A.reference = B.reference and A.row != B.row

1 个答案:

答案 0 :(得分:2)

也许这就是你想要的?

select b."reference", b."row", a."count", b."xxx" 
from b 
join a on a."reference" = b."reference" 
where a."row" not in (select "row" from b)

这将选择B中具有匹配"引用"的所有行。在A中,但在A。" row"并没有出现在"行" B中的值。