select a1,a2,b1,b2 from A inner join B
on A.m = B.m
and A.ab = B.ab
where A.ab =2