Hypothetical data -
tbl1 -
id | date | value1 |
---|---|---|
101 | 2021-01-01 | 200 |
101 | 2021-01-03 | 400 |
tbl2 -
id | date | value2 |
---|---|---|
101 | 2021-01-01 | 600 |
101 | 2021-01-02 | 900 |
My expected result is -
id | date | value1 | value2 |
---|---|---|---|
101 | 2021-01-01 | 200 | 600 |
101 | 2021-01-02 | NaN | 900 |
101 | 2021-01-03 | 400 | NaN |
select * from (select * from tbl1 where id in
(another query)) t1
left join tbl2 as t2 on t1.id = t2.id and t1.date = t2.date
union all
select * from (select * from tbl1 where id in
(another query)) t1
right join tbl2 as t2 on t1.id = t2.id and t1.date = t2.date
where t1.id is null and t1.date is null
I am unable to figure out where am I going wrong.