Find where users match!?
I have some db_table data like this:
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 :-)
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
WHERE fk_user_id IN ( 1,2 ) -- list of users
HAVING COUNT(*) >= 2 -- number of users
if you don't understand what i just said, please at least confirm that the query works :)
Works like a charm... Just what I was looking for ;-) Thanks and I do understand...
Originally Posted by r937