select * from bw bw left outer join az az on az.az_aa = case when bw_anr_aa = 1 OR bw_anr_aa = 2 then bw_anr_aa else null end and az.az_anr = bw.bw_anr and az.az_pos = bw.bw_anr_az