I am using a API to fetch records from a different server and insert into my local database but when a particular field say apiserverID
is duplicate i just want to update fields.
my problem is that i have table structure as
- myPrimaryKey
- apiserverID
- ....
- .....
- .....
- updateDate
now i want simple procedure to update the row if apiserverID
is duplicate.
Only solution i know is i have to check (SELECT) if the key apiserverID exist then update else insert.
but i don't want do programming for this is this possible in one query
EDIT : Main problem is that INSERT ... ON DUPLICATE KEY UPDATE don't work for a particular field, it include all the keys to check duplicity
apiserverID
has anUNIQUE
constraint,ON DUPLICATE KEY
will work as expected. – lanzzapiserverID
– Omesh