I have a master table
#+-----------+----------+-------------+
#| Name | Gender | date |
#+-----------+----------+-------------+
#| Tom | M | 2021-02-15 |
#| Bob | M | 2021-03-02 |
#| Kelly | F | 2021-06-01 |
And a daily table , A daily table can have a data with following conditions
1)Totally new records 2)date column updated for existing records
#+-----------+----------+-------------+
#| Name | Gender | date |
#+-----------+----------+-------------+
#| Tom | M | 2021-03-20 | date updated
#| suzen | F | 2021-06-10 | new records
expected output master table should have all the new records coming in daily plus if any of the name matches with master table then update the new date from daily
#+-----------+----------+-------------+
#| Name | Gender | date |
#+-----------+----------+-------------+
#| Tom | M | 2021-03-20 | date updated form daily
#| Bob | M | 2021-03-02 |
#| Kelly | F | 2021-06-01 |
#| suzen | F | 2021-06-10 | New record
For ease, lets take Name as the unique identifier of both tables.
there is a one way to to join both of these table on full outer and get the result
select (case when d.name is null or d.name='' then m.name
when m.name is null or m.name='' then d.name
else m.name end) as name,
(case when d.gender is null or d.gender ='' then m.gender
when m.gender is null or m.gender ='' then d.gender
else m.gender end) as gender,
(case when d.date is null or d.date ='' then m.date
when m.date is null or m.date ='' then d.date
else d.date end) as date
Form master m full outer join daily d on
on m.name=d.name
What is the way to achieve the expected output in better and more performant way