select * from bw bw left outer join ua ua on ua.ua_aa = case when bw_aa = 1 OR bw_aa = 2 then bw_aa else null end and ua.ua_anr = bw.bw_ak and ua.ua_az = bw.bw_az and ua.ua_pos = bw.bw_ua