MySQL Forums
Forum List  »  Newbie

Re: Mod or delete record if only one field matches, and add new record if one specific field does not exist
Posted by: Barry Galbraith
Date: January 11, 2018 10:10PM

>There's no "magic" statement to do everything in one go.
Situation is made for INSERT ... ON DUPLICATE KEY UPDATE

You need to define a UNIQUE INDEX on the hostname field.
Then you can INSERT, unless the hostnameT already exists, then you can update whatever fields you want.

https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html

Good luck,
Barry.

Options: ReplyQuote


Subject
Written By
Posted
Re: Mod or delete record if only one field matches, and add new record if one specific field does not exist
January 11, 2018 10:10PM


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.