Reputation: 7327
For some reason this is not coming to me, and I do not see this specific question answered where there are two conditions. I want to update my_table for the following two conditions:
Example of before and after two example updates:
In this exable vin 12345 exist so just the price is update as it's different, in the other example vin 55555 wasn't in the table so it's created.
Upvotes: 0
Views: 32
Reputation: 1841
MySql supports a conditional insert/update - check https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html
INSERT INTO my_table (vin,price) VALUES (12345, 7777)
ON DUPLICATE KEY UPDATE price=7777;
Upvotes: 2