I need a select statement which finds values from Column B
which occurs in all distinct values for A
. Meaning in my example it would return: x
since x
occurs in every value of A
. (1,2,3 and 4)
I don't know which values are in Column B
so I can't specify this in my query. How can I achieve this in SQL Server 2014?
+---+----+
| A | B |
+---+----+
| 1 | x |
| 2 | x |
| 3 | y |
| 4 | y |
| 3 | x |
| 4 | x |
+---+----+
Best Answer
Count distinct A grouping by B, and return those where count(distinct A) match.