MySQL Forums
Forum List  »  Newbie

Re: INSERT... ON DUPLICATE KEY UPDATE
Posted by: Barry Galbraith
Date: April 20, 2015 06:29PM

Does this work for you?
INSERT INTO import_io_mysql (tournament, year, name, thru, total) VALUES ('RBC Heritage','2015', 'Jordan Spieth', '56', '-12') ON DUPLICATE KEY UPDATE (tournament='RBC Heritage', year='2015', thru='56', total='-12');

You can't update the field that caused the UNIQUE KEY violation, but all the others are fair game.

BTW, what happens if there is a second Jordan Spieth enters your competition?

In the real world, a name tends not to be a unique identifier. The company I work for has about 20,000 employees, and at times there has been 3 of us with the same name. They use a unique employee id to identify us. The employee id is good for life because some employees leave, and come back. They get back their same employee id.

Good luck,
Barry.

Options: ReplyQuote


Subject
Written By
Posted
Re: INSERT... ON DUPLICATE KEY UPDATE
April 20, 2015 06:29PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.