Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficient way to store unordered pair in a mysql table

I am working with twitter data and need to store uid and friendId pair in a mysql table. My purpose is to create a network of friends and followers with the help of the table later.

I want to avoid duplicate pairs like (uid, friendId) and (friendId, uid) in the table.

Thank you

like image 443
s2n Avatar asked Nov 05 '22 05:11

s2n


1 Answers

to avoid duplicate pairs do check uid < friendId before inserting.

like image 51
triclosan Avatar answered Nov 07 '22 20:11

triclosan