Insert if DNE else update Mysql row -
i trying `on duplicate key update' keeps adding new row instead of updating.
insert favorites (userid, topicid) values ('2', '50') on duplicate key update active = 0;
my favorites table set follows:
favoritesid (ai) userid topicid active (boolean)
if userid , topicid exist (both of them in same row), want change active
0.
is possible?
in order hit on duplicate key
key has exists prior of insert. if there aren't unique keys in there, won't tu use it.
either add unique key or have query first find out if value exists in table before inserting.
Comments
Post a Comment