Answer the question
In order to leave comments, you need to log in
How to add or update row in MySQL if values in columns are duplicate?
Good evening/afternoon/morning everyone.
We have a table table with somestring, userid, objectid columns.
How can I check in one query if a string with certain values exists (eg userid=2,objectid=34) and if the string is found, update somestring as somestring="ok"?
If such a string does not exist, create it.
The userid column can have a bunch of rows with a value of 2, just like with objectid 34 (many-to-many), but there can't be more than one relationship row 2-34.
Previously, I googled on this issue and found INSERT ON DUPLICATE KEY, but due to the meager knowledge of SQL, this is an overwhelming question for me.
Thank you very much everyone for your help!
Answer the question
In order to leave comments, you need to log in
add unique index (userid,objectid)
https://dev.mysql.com/doc/refman/5.0/en/insert-on-...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question