SQL Server多个LEFT JOIN,一对多

时间:2011-10-07 11:48:45

标签: sql join

我正在寻找一种从一个源表到多个表执行多个连接的方法。类似于以下内容:

SELECT a.NAME, b.address, c.phone
FROM tblname a
LEFT JOIN tbladdress b ON a.nid = b.nid

我还想同时在电话桌tblPhone上执行左连接:

tblname a left join tblPhone c on a.PID = c.PID

尽我所能,我无法看到如何将其放入一个查询中。

3 个答案:

答案 0 :(得分:16)

您可以根据需要多次重复JOIN条款,例如:

SELECT a.NAME
    ,b.address
    ,c.phone
FROM tblname a
LEFT JOIN tbladdress b ON a.nid = b.nid
LEFT JOIN tblPhone c ON a.PID = c.PID

答案 1 :(得分:2)

SELECT a.name, b.address, c.phone 
FROM tblname a 
left join tbladdress b on a.nid = b.nid
left join tblPhone c on a.PID = c.PID;

答案 2 :(得分:0)

SELECT a.name, b.address, c.phone 
FROM (tblname a 
  left join tbladdress b on a.nid = b.nid) c 
left join tblPhone d on c.PID=d.PID