From the MySQL docs:
If you specify ON DUPLICATE KEY UPDATE, and a row is inserted that would cause a duplicate value in a UNIQUE index or PRIMARY KEY, MySQL performs an UPDATE of the old row.In other words, the database will delete the existing entry and replace it with the data in the UPDATE statement.
If you wish to check if the key already exists then you simply issue a SELECT statement on that key and see if it returns any result.
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial DeltronicsIn reply to Re: return primary key if duplicate entry exists?
by CountZero
in thread return primary key if duplicate entry exists?
by diyaz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |