I have a table with these two columns
+------+------+
|id |type |
+------+------+
|1 |A |
+------+------+
|1 |B |
+------+------+
|2 |B |
+------+------+
|3 |A |
+------+------+
|3 |B |
+------+------+
|3 |C |
+------+------+
|4 |A |
+------+------+
|4 |A |
+------+------+
and I want to get rows only with duplicate id that has value A and B for Type column
It should look something like this:
+------+------+
|id |type |
+------+------+
|1 |A |
+------+------+
|1 |B |
+------+------+
|3 |A |
+------+------+
|3 |B |
+------+------+
I tried the query below which does print out rows with only the duplicate ids but wasn't able to get rows with value A and B only
select id, type from table s1
where (select count(id) from table s2 where s2.id = s1.id and type in ('A', 'B')) > 1
group by id, type
order by id