I have a SQL query result
| col1 | col2 |
|---|---|
| A1 | C1 |
| A1 | C2 |
| A2 | C1 |
| A3 | C1 |
| A3 | C2 |
This is the SQL
SELECT
col1, col2
FROM
table
WHERE
col2 = 'C1' OR col2 = 'C2'
GROUP BY
col1, col2
Now the question is, how can I get a result where col2 must have both C1 and C2 values, like this (As you can see the A2 is not in the list, since it doesn't have the 'C2' unlike the 'A1' and 'A3')
| col1 | col2 |
|---|---|
| A1 | C1 |
| A1 | C2 |
| A3 | C1 |
| A3 | C2 |
Update : If col1 and col2 are from 2 table
SELECT
table.col1, table2.col2
FROM
table
INNER JOIN
table2
ON
table2.col3 = table.col3
WHERE
table2.col2 = 'C1'
OR
table2.col2 = 'C2'
GROUP BY
table.col1, table2.col2