mysql - How can I efficiently store a 2-way "like" system similar to Tinder? -


on tinder, when 2 members each other, "match" , able communicate. if 1 member likes another, it's not match.

i'm trying store "like" system in mysql can't figure out best way that's efficient. setup right now.

mysql> desc likes_likes; +--------------+----------+------+-----+---------+----------------+ | field        | type     | null | key | default |          | +--------------+----------+------+-----+---------+----------------+ | id           | int(11)  | no   | pri | null    | auto_increment | | from_user_id | int(11)  | no   | mul | null    |                | | to_user_id   | int(11)  | no   | mul | null    |                | | value        | int(11)  | no   |     | null    |                | | created_at   | datetime | no   |     | null    |                | | updated_at   | datetime | yes  |     | null    |                | +--------------+----------+------+-----+---------+----------------+ 6 rows in set (0.00 sec) 

to find matches, query like...

select to_user_id likes_likes from_user_id = my_id , value = 1 , .... don't know how join same table here. 

how perform query on table? if it's not efficient, what's better structure store model?

1 like, 0 not like. 2 values.

select a.from_user_id usera, b.from_user_id userb likes_likes join likes_likes b   on a.from_user_id = b.to_user_id   , a.to_user_id = b.from_user_id   , a.id <> b.id a.value = 1   , b.value = 1 

Popular posts from this blog