Ryan Hamilton
01/31/2023, 3:24 PMjavier ramirez
01/31/2023, 4:07 PMRyan Hamilton
01/31/2023, 4:23 PMjavier ramirez
01/31/2023, 4:57 PMRyan Hamilton
01/31/2023, 4:59 PMjavier ramirez
01/31/2023, 5:01 PMBolek Ziobrowski
01/31/2023, 5:08 PMselect a.*,b.* from a left join b on X --A + A&B
union all
(
select a.*,b.* from b left join a on X --B+A&B
except
select a.*,b.* from b join a on X -- A&B
)
alternative would be something like :
select a.*,b.* from a left join b on X --A + A&B
union all
select * from
(
select a.*,b.* --B
from b left join a on X)
where a.ts is null -- any non-nullable column
)
Matt
01/31/2023, 7:47 PM/* CTE to make example self-contained */
with price_stuff as (
select '2019-10-17T00:00:00.000000Z'::timestamp as ts, 'price_1' as price
union all select '2019-10-17T00:00:00.400000Z'::timestamp, 'price_2'
union all select '2019-10-17T00:00:03.000000Z'::timestamp, 'price_3'
),
size_stuff as (
select '2019-10-17T00:00:00.000000Z'::timestamp as ts, 'size_1' as size
union all select '2019-10-17T00:00:02.400000Z'::timestamp, 'size_4'
)
/* In general, this filter is a useful pattern */
select p.ts, p.price, s.size
from
price_stuff p
left outer join size_stuff s on ( p.ts = s.ts )
union all
select s.ts, p.price, s.size
from
size_stuff s
left outer join price_stuff p on ( p.ts = s.ts )
where p.ts is null -- filter out duplicates
/* In this case, I think Union would be identical */
select p.ts, p.price, s.size
from
price_stuff p
left outer join size_stuff s on ( p.ts = s.ts )
union -- not ALL
select s.ts, p.price, s.size
from
size_stuff s
left outer join price_stuff p on ( p.ts = s.ts )
Ryan Hamilton
01/31/2023, 7:58 PMBolek Ziobrowski
02/01/2023, 8:13 AMMiguel Arregui
02/01/2023, 8:19 AM