I have a SQL table which contains UserID and AppID. Now i need a select query which selects all appid’s which are used by all userid’s
For example:
x
UserID AppID
1 35
1 42
2 35
2 42
3 35
3 77
In this example I would only want AppID 35 because it’s used by all UserID’s.
Advertisement
Answer
You can do aggregation :
select appid
from table t
group by appid
having count(*) = (select count(distinct userid) from table);
Use distinct
inside count()
in case appid
has duplicate userid.