Q:

fetching combination of records using sql query

I need a query which fetch records 
1 A
1 P
1 D
1 A
2 A
2 D
2 A
3 A
3 A
3 A
4 A
4 D
4 A
4 D

I want to select A and D combination records.
 That is I need to select 
2 A
2 D
2 A
4 A
4 D
4 A
4 D
 but I don't want to select 1 and 3 records
 Could you please help me.

A:

Try this:
select * from yourtable where column1 in 
( 
 select column1
 from yourtable
 group by column1
 having count(distinct column2) = 2 -- Only 2 different values should be possible
 and max(column2) = 'D' 
 and min(column2) = 'A' --Useful if B or C are possible values)

