-1

I am currently having troubles with filtering my SQL records. I need something like what it results in the following concept: Table is

A   B
1   1
1   3
2   1
2   2
2   3
2   4
3   1
3   2

I want to select value of A , where B=1 and B=2 And B=3 when same A .... result is

A
2

Please help

GMB
  • 216,147
  • 25
  • 84
  • 135

1 Answers1

1

You can use aggregation:

select a
from mytable
where b in (1, 2, 3)
group by a
having count(*) = 3

This assumes no duplicates in the table - else, you need to change the having clause to:

having count(distinct b) = 3
GMB
  • 216,147
  • 25
  • 84
  • 135
  • Thanks , But when table has groups of three records (A, B with same values) , result is incorrect. if exist thrice same record, like A = 4 ,B=1, not success. help – PLAA Hemantha Aug 15 '20 at 09:45