I’m a little bit confused as to what ON DUPLICATE KEY UPDATE does. What I’m looking for is something that will check an INSERT INTO SQL command and if any row is a duplicate do not update that row. Now if anything in that row is not a duplicate (but some is), I’d like to replace that row with the updated information.
Is this possible using basic MYSQL or am I going to have to pull all the data first, then cross check it. I’d rather not do that as all I’m trying to do is cache a decent amount of data once a day.
"INSERT INTO years (date,year,venue,city,state,country,showid) VALUES (?,?,?,?,?,?,?)"
ON DUPLICATE KEY UPDATEsimply performs theSETstatements you provide to it in the case of a duplicate key. It does not compare individual column values and only update the differing ones. It does sound like it will work for what you want to do as long as you have the proper column(s) defined asUNIQUE KEYorPRIMARY KEY.However, what I normally do is run the insert and then catch the error and perform a differing action if I need to. This has the down side of issuing 2 queries if there is a duplicate but in my opinion it’s much more maintainable.
Example: