If I have two rows in two different tables such as:
Table Name - Old
id | title | views |
---|---|---|
wx | How to clean a drill | 30 |
np | Craziest Fails | 400 |
zo | Eating Challenge | 8 |
lf | JavaScript Tutorial | 0 |
Table Name - New
id | title | views |
---|---|---|
wx | How to clean a drill | 30 |
np | Craziest Fails | 450 |
zo | This was a mistake | 8 |
lf | Learning JavaScript | 20 |
The differences in the two tables are as follows:
- Row 1 (id=wx):
title
andviews
have not changed. - Row 2 (id=np): The
views
has increased, while thetitle
is the same. - Row 3 (id=zo): The
title
has changed, while theviews
are the same. - Row 4 (id=lf): Both
title
andviews
have changed.
Desired Result
I want a query that returns Table Name - New, but any values that haven't changed from Table Name - Old should be null
, other than id
. If the entire row has not changed, then the row should not be returned.
id
is constant and does not change.
Query Result
id | title | views |
---|---|---|
np | null |
450 |
zo | This was a mistake | null |
lf | Learning JavaScript | 20 |
The closest I have gotten is
SELECT * FROM new EXCEPT SELECT * FROM old;
but this does not null
out the unchanged values.
Would be grateful for any help.