'Select record table mysql

I'm working on a small search engine project and I need some help with a SQL query. My table looks like this (example):

user_id  |       group_id
---------------------------
1        |        2
2        |        2
2        |        3
3        |        2

I would like to look for : user_id who has group_id = 2 and 3 So a possible result would be:

user_id   |       group_id
---------------------------
2         |        2
2         |        3

How should the select query look like?



Solution 1:[1]

I will suppose your table name is users and we will select only two columns user_id and group_id from the users table

SELECT user_id, group_id FROM users WHERE group_id IN (2, 3);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ihtisham Khan