【问题标题】:Complex joins on postgresqlpostgresql 上的复杂连接
【发布时间】:2018-07-27 16:06:39
【问题描述】:

有两个表A和B。从A中选择所有但如果存在于B中,则从B中选择记录而不是A。所以结果应该有来自A的记录(不存在于B)+ B(仅匹配于A)

【问题讨论】:

标签: postgresql join


【解决方案1】:

来自 A(不存在于 B)+ B(仅匹配于 A)的记录

假设 A 和 B 具有相同的结构,类似这样:

(select * from A
  EXCEPT
 select * from B) -- A records that don't exist in B
UNION             -- Plus
( select * from B
   INTERSECT
  select * from A)  -- B records that exist in A

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多