请为您提供帮助。
表结构如下所示:
现在,如果我有一个LoanId,我如何找到已使用给定LoanId的财产ownerId的所有属性?
我现在有以下内容,但看起来很尴尬:
Select po.OwnerId, po.PropertyId
from Property
join PropertyOwner po on po.PropertyId= Property.PropertyId
join PropertyOwner po2 on po2.OwnerId = po.OwnerId
join Property pp on po2.PropertyId= pp.PropertyId and pp.LoanId = @_givenLoanId
有更好的方法吗?
答案 0 :(得分:1)
存在者是对您正在做的事情的更直接的解释:
Select po.OwnerId, po.PropertyId
from PropertyOwner po
where exists (select 1
from Property p2 join
PropertyOwner po2
on p2.PropertyId = po2.PropertyId
where po2.OwnerId = po.OwnerId and
p2.LoanId = @_givenLoanId
);