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

Popular posts from this blog

ios - Memory not freeing up after popping viewcontroller using ARC -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -