already searched for such topics and found 2 different solutions but noone works.
My table has structure | ID (auto_increment primary_key) | UID (int) | FAV_ID (int) |
I need to insert new record to this FAV_TABLE if UID and FAV_ID (both) already exist.
Example of my query:
INSERT INTO FAV_TABLE (uid, fav_id) VALUES ($u_id,$s_id) ON DUPLICATE KEY UPDATE uid = uid
or this one
INSERT IGNORE FAV_TABLE (uid, fav_id) VALUES ($u_id,$s_id);
As mysql manuals says this query doesn't add record only if PRIMARY_KEY is the same. And I need query not to add record if pair uid+fav_id is unique. Any solutions? Thank you
You need to add a UNIQUE KEY
on those columns:
ALTER TABLE FAV_TABLE ADD UNIQUE KEY(uid, fav_id);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With