select A.* from A 
where exists (select * from (select id,count(*) aa from B group by id ) D
where A.id = D.id)