TableA :
ID,
mail,
team,
[other columns]
TableB :
ID,
mail,
team,
[other columns]
ID is the primary key in both tables. I need to work through every row in TableB and :
- If ID doesn’t exist in TableA, insert new row – using columns
ID,mail,team (only) - If ID does exist in TableA, update row with new value for mail (only)
- ID’s that exist in TableA but not TableB row should
remain unchanged
I have :
INSERT INTO tablea (id,mail,team) (SELECT id,mail,team FROM tableb)
ON DUPLICATE KEY update tablea SET tablea.mail=tableb.mail;
This doesn’t work – I think I need a join to make the last SET command valid, but not sure on this part, can anyone help?
Many Thanks
As documented under
INSERT ... ON DUPLICATE KEY UPDATESyntax:Therefore: