select *
from Urge join OweDom_Sub on Urge.lSubID=OweDom_Sub.lID and Urge.lMID=0
join OweDom on Urge.lMID=OweDom.lID where Urge.lMID<>0
join RentContract on OweDom.sCntID=RentContract.sContractID
select * from Urge A join OweDom_Sub B on A.lSubID=B.lID
join RentContract C on B.sCntID=C.sContractID where A.lMID=0
union all
select *
from Urge D join OweDom E on D.lMID=E.lID join RentContract F on E.sCntID=F.sContractID
where D.lMID<>0