I have a table structure as under:
ID A B -- --- ----- 1 a a1 2 b b1 3 a a2 4 c a1 5 b b2
Use a GROUP BY and a COUNT.
GROUP BY
COUNT
SELECT A FROM yourtable WHERE B IN ('a1', 'a2') GROUP BY A HAVING Count(DISTINCT B) > 1