I have a very simple item ownership table with these two columns:
UserID, ItemID
There is an index on UserID, but not ItemID.
I have a set S of 10-40 specific ItemID
s (in my queries they are just a comma delimited list of integers).
I want to find all UserID
s that own at least X (distinct ItemID
s) of the items in S.
I am using MSSQL if it matters. Can this be done efficiently?