SQL Server 多个 LEFT JOIN,一对多

发布于 2024-12-08 13:12:59 字数 312 浏览 0 评论 0原文

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

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

尽我所能尝试,但我不知道如何将其放入一个查询中。

I am looking for a way to perform multiple joins from one source table to more than one table. Similar to the following:

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

I also want to perform a left join on the Telephone table tblPhone at the same time:

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

Try as I might I can't see how to put this into one query.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吃兔兔 2024-12-15 13:12:59

您可以根据需要多次重复 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

You can simply repeat your JOIN clauses as many times as is needed, e.g.:

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
只有一腔孤勇 2024-12-15 13:12:59
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;
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;
时光清浅 2024-12-15 13:12:59
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
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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文