MySQL Forums
Forum List  »  Newbie

INSERT... ON DUPLICATE KEY UPDATE
Posted by: Alan Crookes
Date: April 19, 2015 02:03PM

Hi,

I'm trying to construct the following statement to either update or insert a new record.

I only have one unique field called NAME.

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', name='Jordan Spieth', thru='56', total='-12');

I'm a little bit confused if I need values both before and afer the ON DUPLICATE KEY UPDATE section?

Can someone please clarify what I need. I am hoping to use it with PDO and PHP to give me something like this

INSERT INTO import_io_mysql (tournament, year, name, thru, total) VALUES (:tournament, :year', :name, :thru, :total) ON DUPLICATE KEY UPDATE tournament=:tournament, year=:year, name=:name, thru=:thru, total=:total");

Options: ReplyQuote


Subject
Written By
Posted
INSERT... ON DUPLICATE KEY UPDATE
April 19, 2015 02:03PM


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.