I need to select the users only when id_user_a and id_user_b match each other for a given user id.
users // SQL Statements: http://pastebin.com/w34qQv0g
id username
1 user1
2 user2
3 user3
4 user4
matches
id_user_a id_user_b
1 2
2 1
1 4
4 1
As you can see above, for a given user id 1, the id’s that match in both directions in matches table are id=2 and id=4. Because the first match with the second and vice-versa (1-2 and 2-1 :: 1-4 and 4-1).
And for a given id 4, just one id match in both directions (1-4 and 4-1) then just the id=1 match in both directions with the id 4. I want to select the id’s that matches in both directions for a given id. The concept is fairly clear, isn’t it ? but, How I can do that in a select statement ? Could anyone help me ? Thank you.
For id 4:
And change 4 to parameter.