im doing a quite simple database in which i need to connect people as friends.
In my first column i have user_id and in the second one i have friend_id. What i want to achieve is to prevent a duplicate entry.
for example i want to have something like this:
user_id ; friend_id
1 ; 2
1 ; 3
1 ; 4
and so on
and prevent this:
1 ; 2
1 ; 3
1 ; 3
1 ; 4
1 ; 4
iv tried everything. If i set user_id as primary or unique, it wont allow me 2 entries with user_id = 1;
any help? thanks
As this answer states, a composite primary key such as
(user_id, friend_id)won’t allow you to use the index if you query onlyfriend_id. You can alternatively create aUNIQUEkey on(user_id, friend_id).