in reply to return primary key if duplicate entry exists?
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 Deltronics
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: return primary key if duplicate entry exists?
by diyaz (Beadle) on Jan 24, 2016 at 15:44 UTC | |
by diyaz (Beadle) on Jan 24, 2016 at 15:50 UTC | |
by poj (Abbot) on Jan 24, 2016 at 16:07 UTC | |
by CountZero (Bishop) on Jan 24, 2016 at 19:12 UTC | |
by diyaz (Beadle) on Jan 24, 2016 at 19:45 UTC | |
| |
by diyaz (Beadle) on Jan 24, 2016 at 19:07 UTC | |
by CountZero (Bishop) on Jan 24, 2016 at 18:45 UTC | |
by diyaz (Beadle) on Jan 24, 2016 at 18:58 UTC | |
by CountZero (Bishop) on Jan 24, 2016 at 19:58 UTC |