I have a table like this:
--------------------- | id | user | group | --------------------- | 0 | 103 | 27 | | 1 | 107 | 31 | | 2 | 103 | 32 | | 3 | 112 | 31 | | 4 | 135 | 64 | | 5 | 135 | 66 | ---------------------
This is a table of groups and users, and, as you can see, there can be records with the same user and different groups. How can I choose, for example, records with the same user and two groups - 27 and 32? This will be the same user.
So how can I do this?
EDIT: To show the expected result, I wrote a sample:
SELECT user FROM table ... (maybe WHERE group = 27 AND group = 32)
- gives user id 103
EDIT 2: I found it!
Here is a query that works fine for me:
SELECT * FROM table WHERE `user` in ( SELECT `user` FROM table WHERE `group` = <needed_group_1> ) AND `group` = <needed_group_2>
Thank you all for your help, I found all your answers helpful!
source share