日期:2014-05-18  浏览次数:20477 次

Left Join 多表是怎么连接的?
查询:
SQL code
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怎么做?


------解决方案--------------------
table1左连接table2
table1左连接table3
------解决方案--------------------
LEFT JOIN table3 ON a.code=b.code不对的吧
------解决方案--------------------
SQL code

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 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
------解决方案--------------------
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有什么区别?
------解决方案--------------------
LEFT JOIN table3 ON a.code=b.code
--------------
这句代码有问题。

------解决方案--------------------
SQL code

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
FROM ((table1 a LEFT JOIN table2 b ON a.code = b.code)
LEFT JOIN table3 c ON a.code = c.code)
这个问题看似很基础!
------解决方案--------------------
LEFT JOIN table3 ON a.code=b.code 
上楼的兄弟,这句问题出在哪里?
------解决方案--------------------
http://topic.csdn.net/u/20071217/10/d1add9f1-b8d7-4d7e-b54a-7d0fdaf0210e.html

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


学习ing~~:)
------解决方案--------------------
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)的行

------解决方案--------------------
LEFT JOIN table3 ON a.code=b.code
上楼的兄弟,这句问题出在哪里?
-----------------------------
你要连接的是 table3
但是连接条件中写的却是 a和b,也就是table1和table3,没有table3是不行了。
所以给table3起个别名,然后在连接条件中指定条件。

------解决方案--------------------
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 有区别吗?
------解决方案--------------------
LEFT JOIN table3 ON a.code=b.code的结果和select * from table1,table3一样的
------解决方案--------------------
查询结果和select cName from table1 有区别吗?
-------------------
我想楼主是举例,实际上并不会是这种连接条件。
------解决方案--------------------