Left Join 多表是怎么连接的?

yumanqing 2007-12-27 02:27:20
查询:
select a.cName
from table1 a LEFT JOIN table2 b ON a.code=b.code
LEFT JOIN table3 ON a.code=b.code


===这三个表的连接关系是怎么样的?
table1左连接table2
是table1连接table3还是table2连接table3
现在想table1同时连接table3怎么做?
...全文
4237 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
xdh 2012-07-20
  • 打赏
  • 举报
回复
楼主最终明白了吗?答案是怎样的呢?
  • 打赏
  • 举报
回复
我也在找这个~
WhyAndAnswer 2007-12-27
  • 打赏
  • 举报
回复
有区别的,当code在表2不唯一的时候,返回结果是多条
对的
qiule 2007-12-27
  • 打赏
  • 举报
回复 1
select a.cName
from table1 a
LEFT JOIN table2 b ON a.code=b.code
LEFT JOIN table3 c ON a.code=c.code
jackyerror 2007-12-27
  • 打赏
  • 举报
回复
查询结果和select cName from table1 有区别吗?
-------------------
我想楼主是举例,实际上并不会是这种连接条件。

-----------------------------
有区别的,当code在表2不唯一的时候,返回结果是多条
hui_hui_2007 2007-12-27
  • 打赏
  • 举报
回复
查询结果和select cName from table1 有区别吗?
-------------------
我想楼主是举例,实际上并不会是这种连接条件。
WhyAndAnswer 2007-12-27
  • 打赏
  • 举报
回复
LEFT JOIN table3 ON a.code=b.code的结果和select * from table1,table3一样的
WhyAndAnswer 2007-12-27
  • 打赏
  • 举报
回复
select a.cName
from table1 a
LEFT JOIN table2 b ON a.code=b.code
LEFT JOIN table3 c ON a.code=c.code
查询结果和select cName from table1 有区别吗?
hui_hui_2007 2007-12-27
  • 打赏
  • 举报
回复
LEFT JOIN table3 ON a.code=b.code
上楼的兄弟,这句问题出在哪里?
-----------------------------
你要连接的是 table3
但是连接条件中写的却是 a和b,也就是table1和table3,没有table3是不行了。
所以给table3起个别名,然后在连接条件中指定条件。
米多 2007-12-27
  • 打赏
  • 举报
回复
select a.cName
from table1 a
LEFT JOIN table2 b ON a.code=b.code
LEFT JOIN table3 c ON a.code=c.code

过程是这样的:
1, 首先table1左链接table2,得到一个中间结果,该中间结果包括table1的所有行以及table2中与table1匹配条件(a.code=b.code)的行
2, 该中间结果左链接table3,得到最终的行集,该行集中包括上一步的中间结果的所有行以及table3中与中间结果匹配条件(a.code=c.code)的行
yiyi_wx 2007-12-27
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20071217/10/d1add9f1-b8d7-4d7e-b54a-7d0fdaf0210e.html

看看这个吧,我前两天刚问过的,一开始没什么实践,很迷茫,但在实际中用多了会慢慢明白的:)


学习ing~~:)
tangkai23 2007-12-27
  • 打赏
  • 举报
回复
LEFT JOIN table3 ON a.code=b.code
上楼的兄弟,这句问题出在哪里?
honghuali 2007-12-27
  • 打赏
  • 举报
回复
SELECT
FROM ((table1 a LEFT JOIN table2 b ON a.code = b.code)
LEFT JOIN table3 c ON a.code = c.code)
这个问题看似很基础!
hui_hui_2007 2007-12-27
  • 打赏
  • 举报
回复

select a.cName
from table1 a LEFT JOIN table2 b ON a.code=b.code
LEFT JOIN table3 c ON a.code=c.code
hui_hui_2007 2007-12-27
  • 打赏
  • 举报
回复
LEFT JOIN table3 ON a.code=b.code
--------------
这句代码有问题。
WhyAndAnswer 2007-12-27
  • 打赏
  • 举报
回复
select a.cName
from table1 a LEFT JOIN table2 b ON a.code=b.code
LEFT JOIN table3 c ON a.code=c.code
怎么试验得出来,这个语句和select cName from table1有什么区别?
yumanqing 2007-12-27
  • 打赏
  • 举报
回复
可我试验好象不是这样的呀
WhyAndAnswer 2007-12-27
  • 打赏
  • 举报
回复
select a.cName
from table1 a LEFT JOIN table2 b ON a.code=b.code
LEFT JOIN table3 c ON a.code=c.code
table1左连接table2,又左连接table3
tim_spac 2007-12-27
  • 打赏
  • 举报
回复

select a.cName
from table1 a
LEFT JOIN table2 b ON a.code=b.code
LEFT JOIN table3 c ON a.code=c.code
WhyAndAnswer 2007-12-27
  • 打赏
  • 举报
回复
LEFT JOIN table3 ON a.code=b.code不对的吧
加载更多回复(1)

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧