C
C
coden552015-12-20 20:27:24
MySQL
coden55, 2015-12-20 20:27:24

Select friends from the table?

Friends table with two columns from_user_id and to_user_id
The presence of an entry for example 1 - 3 indicates an unconfirmed friend request. The presence in addition of a writeback 3 - 1 says that 2 users are friends.
Tell me offhand a query how to get all the confirmed friends of a particular user from the table?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Marat, 2015-12-20
@coden55

Something like this (if I understood the question), instead of 5 - the desired value (corrected, after the comment of the author of the topic):

select t2.* from table1 t1,table1 t2 
  where 
     t1.from_user_id=t2.to_user_id and 
     t2.from_user_id=t1.to_user_id and 
     t1.from_user_id=5

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question