Reputation: 2619
I wonder if there is no short way to update a row only if a key exists. I dont want to insert a new row otherwise, so INSERT ON DPULICATE KEY is not working.
For example:
I have a table containing addresses of lets say 200 customer with an primary key on their unique customer id. Now I get a new excel list of 500 addresses containing their updated data. I want to update all of the 200 customers in my table but I dont want to add the 300 other ones.
So I search for something like
UPDATE ON EXISTS
All searches for this keywords lead to INSERT ON DUPLICATE UPDATE. So I hope you can help.
Upvotes: 0
Views: 747
Reputation: 97
I think you can use another way.
for example:
- insert the 500 customer into a new table.
- use nature join to update the 200 customer info.
then you can use update like :
update A set A.address = B.address where A.id = B.id;
then drop the B table.
Upvotes: 1