如何编写这个嵌套查询?

时间:2011-09-24 04:32:06

标签: sql sql-server

这是2个查询。哪一个是正确的?

SELECT link.[xlink:Show].
       Location.[xlink:show],
       link.[xlink:actuate],
       Location.[xlink:actuate], 
  FROM Sem
  JOIN Location AND
         Link join Location ON
         link. link_id = Location.link_id);

错误:关键字“AND”附近的语法不正确。

SELECT link.[xlink:Show],
       Location.[xlink:show],
   link.[xlink:actuate],
       Location.[xlink:actuate],
       Sem.SemRole   
  FROM Sem, Link
  JOIN Location ON link. link_id = Location.link_id);

错误:无法绑定多部分标识符“Sem.SemRoleId”。

1 个答案:

答案 0 :(得分:2)

试试这个:

SELECT LI.[xlink:Show], 
       LI.[xlink:actuate],
       LO.[xlink:show],
       LO.[xlink:actuate],
       S.SemRole   
FROM Sem AS S
INNER JOIN Location AS LO ON S.SemRoleId = LO.SemRoleId 
INNER JOIN Link  AS LI ON LI.link_id = LO.link_id;