[英]CTE not working with extra join clause
Can someone tell me why this returns 0 records when I add the extra join information for [PropertyId]? 有人可以告诉我为什么当我为[PropertyId]添加额外的联接信息时返回0条记录吗? I know this is something simple but, I'm at a loss.
我知道这很简单,但是我很茫然。
declare @ViewId as int;
set @ViewId = 11;
with Views
as
(
select [LiveWireView].[Id], [LiveWireView].[Name], [LiveWireView].[ParentId], [PropertyToViewMap].[PropertyId]
from [LiveWireView]
inner join [PropertyToViewMap] on [PropertyToViewMap].[ViewId] = [LiveWireView].[Id]
where [LiveWireView].[Id] = @ViewId
union all
select [v].[Id], [v].[Name], [v].[ParentId], [p].[PropertyId]
from [LiveWireView] v
inner join [PropertyToViewMap] p on [p].[ViewId] = [v].[Id]
inner join Views on Views.Id = v.ParentId
)
select [PropertyId] from Views;
If you added this join: 如果添加了此联接:
inner join [PropertyToViewMap] p on [p].[ViewId] = [v].[Id]
And are no longer getting results, I think it's same to say that there are no records that meet these conditions. 而且不再获得结果,我认为可以说没有满足这些条件的记录是一样的。 You could test this by converting it to a
LEFT JOIN
and seeing if you get a null value for PropertyId
您可以通过将其转换为
LEFT JOIN
并查看是否获得PropertyId
的空值来进行测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.