I am trying to get from a table those values in column1, that have some values in column2.
For example, I want to get A because it has "1,2,3". (Expected Output of select: A)
SELECT * FROM sample_table WHERE Col2 in (1,2,3) GROUP BY col1
You can use the
HAVING() clause :
SELECT col1 WHERE Col2 in (1,2,3) GROUP BY col1 HAVING COUNT(col2) = 3
This will show only results that have 3 values , and since you filtered only for
1,2,3 , if there are 3, it those 3.
Note : If the values on col2 are not distinct , E.G. it's possible for this data to appear:
A | 1 A | 1 A | 2
DISTINCT inside the parentheses of the count.