首页 > 解决方案 > MSSQL 查询框架

问题描述

我有 3 个表,例如 master 和 2 个子表。我正在使用加入条件,但没有达到预期的客户需求。

在此处输入图像描述

询问:

select * from(
select a.id as mid,b.id,b.val from ##mastertable a right join ##table1 b 
on a.id=b.id ) as c inner join ##table2 d on c.mid=d.id 

请提供任何其他方式来获得正确的结果。

标签: sql-server

解决方案


Try:

Select a.id, b.id, b.val
From (mastertable a
Right Join table1 b 
On a.id = b.id)
Inner Join table2 d
On a.id = d.id;

推荐阅读