I have a table with columns: userid, productid
I want to do the following in one statement: For each member count the number of productids that match the productids for another specified member.
Example table:
userid productid
1 10
1 14
2 10
3 12
3 14
3 10
3 19
4 15
In the above example, if I specified userid 1 then I want to get a result that looks like:
userid matches
2 1
3 2
4 0
The result would look like the above because these are the productids from each user that match the productids from my specified user (1).
In reality I would also want to order it by matches desc and only where matches>0. So it would be:
userid matches
3 2
2 1
Any ideas?