Find where users match!?

I have some db_table data like this:

MyTable:
id fk_user_id fk_data_id
1 1 1
2 2 1
3 1 2
4 3 2
5 2 3
6 3 3
7 1 4
8 2 4

Now what I want to do is to get the fk_data_id from the table where fk_user_id 1 AND 2 matches (That would in this case be 1 and 4). I want to get them out in an array but not sure how to do so?

Can anyone please help… Thank in advance :slight_smile:

SELECT fk_data_id
  FROM db_table
 WHERE fk_user_id IN ( [COLOR="#FF0000"]1,2[/COLOR] ) -- list of users
GROUP
    BY fk_data_id
HAVING COUNT(*) >= [COLOR="#FF0000"]2[/COLOR] -- number of users

note i used >=2 since you are using an auto_increment column in that table, and i’ll bet you haven’t ensured the uniqueness of the user/data combos

if you don’t understand what i just said, please at least confirm that the query works :slight_smile:

Works like a charm… Just what I was looking for :wink: Thanks and I do understand…