Reputation: 1810
How do I get mode of an array record in Mysql?
i.e: 1,2,3,4,5 , 1,3,5
I would like to get out of the table user_friends to get which friends these friends have in common, in this case, 1,3,5. How would I accomplish this?
Upvotes: 1
Views: 78
Reputation: 33697
I'll assume you have a table
user | friend
-------------
6 | 1
6 | 2
6 | 3
6 | 4
6 | 5
7 | 1
7 | 3
7 | 5
then you can do
SELECT *
FROM friends f1
JOIN friends f2 USING (friend)
WHERE f1.user = 6
AND f2.user = 7
and you will get
user | friend | user
--------------------
6 | 1 | 7
6 | 3 | 7
6 | 5 | 7
Upvotes: 3