I am still wondering if there is something like a conditional on duplicate update in MySQL 5.7
I have a table which is updated by different sources.
Let’s assume I have a table
CREATE TABLE t
(
name VARCHAR(100),
value INT,
last update DATETIME
)
I have 3 rows
name | value | lastupdate |
---|---|---|
a | 10 | 2021-01-01 |
b | 20 | 2021-02-01 |
c | 30 | 2021-03-01 |
Now I have some data to be imported
name | value | lastupdate |
---|---|---|
a | 20 | 2021-01-01 |
b | 40 | 2021-01-01 |
c | 60 | 2021-04-01 |
The result of the query should be
name | value | lastupdate |
---|---|---|
a | 20 | 2021-01-01 |
b | 20 | 2021-02-01 |
c | 60 | 2021-03-01 |
Can this be done by one insert query or must I check first if the last update of the existing data in the table is newer then the date of the import data?