So I have a table kind of like the one below.
+----+----------+---------+
| ID | group_id | user_id |
+----+----------+---------+
| 1 | 10 | 9 |
| 2 | 20 | 8 |
| 3 | 10 | 7 |
| 4 | 10 | 6 |
| 5 | 20 | 5 |
+----+----------+---------+
I have an array of user IDs [9,7,6]
and I'd like to get the Group ID where all the IDs are in the same group?
My current query:
SELECT group_id FROM group_user WHERE user_id IN (9,7,6) GROUP BY group_id
Bare in mind I'm not overly familiar with SQL queries.
Thanks
EDIT
I have opened a new question with more detail and my goal.
SQL, check if conversation exists between group
makes sure that all 3 ids are in the same group_id and that they're not in any other group.
http://sqlfiddle.com/#!9/540f96/2
Your query should be:
You can use conditional aggregation to find group_id's which have the required user_id's associated with them.