0

I have a data like below. I need to get the distinct Col 1 values where it has both "aaa" and "bbb" as Col 2 values.

Sorry, just starting to learn SQL on my own.

my table

|--------|----------|
| Col 1  | Col 2    | 
|--------------------
| 1      | aaa      |
| 1      | bbb      |
| 2      | aaa      |
| 2      | ccc      |
| 3      | aaa      |
| 3      | bbb      |
| 3      | ccc      |
|--------|----------|

Result should be below.

|--------|
| Col 1  | 
|--------|
| 1      | 
| 3      | 
|--------|

Thank you.

Strawberry
  • 33,750
  • 13
  • 40
  • 57
dns
  • 1
  • What have you tried so far? Post your query. – RamblinRose Mar 19 '20 at 09:46
  • I have tried to do a subquery, however, it would result to nothing.SELECT DISTINCT Col1 FROM table WHERE Col = '1' AND Col1 IN (SELECT DISTINCT Col1 FROM table WHERE Col = '2') – dns Mar 19 '20 at 09:49

0 Answers0