If I am understanding your question correctly and you want to know how many links User 1 and User 2 share, then you could use this query:
[SQL]SELECT
COUNT(DISTINCT t1.linkid) AS shared_links
FROM
link_favorites t1
INNER JOIN link_favorites t2 ON
t1.linkid = t2.linkid
WHERE
t1.userid = 1
AND t2.userid = 2[/SQL]
Your inclination to use a self-join in your example is pretty close to the mark, except that you could get duplicates and you might as well let MySQL handle the counting. Also, a left join would return all of user 1's links, whether they matched or not.
|