Home > Back-end >  Select all Id's with column containing all values
Select all Id's with column containing all values

Time:02-01

What is the select query to achieve the following :

Id Value
1 A
1 B
2 A
2 C
3 A
3 B
3 C

Expected result : 3

Select All Id's having A and B and C as Value

CodePudding user response:

You could aggregate and count the distinct values:

select Id
from t
where value in ('A','B','C')
group by id
having Count(distinct value) = 3;
  • Related