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):
titleandviewshave not changed. - Row 2 (id=np): The
viewshas increased, while thetitleis the same. - Row 3 (id=zo): The
titlehas changed, while theviewsare the same. - Row 4 (id=lf): Both
titleandviewshave 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.