By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table `t1` (
`date` date,
`value` int
);
create table `t2` (
`date` date,
`value` int
);
insert into `t1` (`date`, `value`)
values ("2022-01-01", 1),
("2022-03-01", 3),
("2022-04-01", 4);
insert into `t2` (`date`, `value`)
values ("2022-01-01", 1),
("2022-02-01", 2),
("2022-04-01", 4);
Records: 3 Duplicates: 0 Warnings: 0
Records: 3 Duplicates: 0 Warnings: 0
select *
from `t1`
left join `t2` on `t2`.`date` = `t1`.`date`
union
select *
from `t1`
right join `t2` on `t2`.`date` = `t1`.`date`;
date | value | date | value |
---|---|---|---|
2022-01-01 | 1 | 2022-01-01 | 1 |
2022-03-01 | 3 | null | null |
2022-04-01 | 4 | 2022-04-01 | 4 |
null | null | 2022-02-01 | 2 |
select *
from `t1`
left join `t2` on `t2`.`date` = `t1`.`date`
where `t1`.`date` > "2022-01-01"
union
select *
from `t1`
right join `t2` on `t2`.`date` = `t1`.`date`
where `t1`.`date` > "2022-01-01";
date | value | date | value |
---|---|---|---|
2022-03-01 | 3 | null | null |
2022-04-01 | 4 | 2022-04-01 | 4 |
select *
from `t1`
left join `t2` on `t2`.`date` = `t1`.`date`
where `t1`.`date` > "2022-01-01"
union
select *
from `t1`
right join `t2` on `t2`.`date` = `t1`.`date`
where `t2`.`date` > "2022-01-01";
date | value | date | value |
---|---|---|---|
2022-03-01 | 3 | null | null |
2022-04-01 | 4 | 2022-04-01 | 4 |
null | null | 2022-02-01 | 2 |