I have 2 tables, ‘interests’ and ‘users_interests’.
‘users_interests’ just has userid and interestid fields.
‘interests just has an id and a name.
I simply need to find userid’s who have more than 3 interest ID’s in common. I have been told that a Self Join is involved, but I cannot seem to get this to work.
Someone said something like this could work:
SELECT
others.userid
FROM interests AS user
JOIN interests AS others
USING(interestid)
WHERE user.userid = 2
GROUP BY
others.userid
ORDER BY COUNT(*) DESC
But I’m having no luck with it.
Note the occurence of the
useridwe’re basing our search on (2) on two places in the code