SQL 多表关联 中,左表右表指哪些表?

时间:2021-08-22 20:11:08
大家好请帮我个问题,我想了没想好,想得到一个肯定的答案!先谢谢了!

左表右表指哪些表?
select * from 
table_1 as a inner join table_2 as c
on
a.id=b.id 
inner join table_3 as c
on
b.isbn=c.isbn 


疑问中............
第一种认为:
认为最左边的表左表 table_1
右表就是除了左表的其它表,而不是最右边的表
所以这里的左表是 table_1,那右表是table_2,table_3

第二种认为:
table_1 是table_2的左表,table_2是table_3的左表

还请牛人指点!

27 个解决方案

#1


外连接才分吧

#2


還沒注意過,結果一致就好

#3


nolast02(小明)
不好意思写错了!真不对住啊!

left join
right join

#4


这个左右是相对的
只要理解外连接的实质就行了
table1 left join table2 和 table2 right join table1是等价的

#5


接分

#6


nolast02(小明)
谢谢,请再看下的问题!
select * from 
table_1 as a left join table_2 as c
on
a.id=b.id 
left join table_3 as c
on
b.isbn=c.isbn 

我想问的是在这个sql语句中左表是谁,右表又是谁,上面也写了我的疑问,
而不是left join 与right join 对比
请帮解答下!谢谢!

#7


楼主

table_1 左连接 table_2 以table_1为基础进行连接运算,得到新表(#table)。
#table 右连接 table_3 以table_3为基础进行连接运算,得到最终结果。

左右表很重要吗?

#8


楼主发的都是内连接,左右表的位置没有什么关系

#9


哦,有点懂了,你说的是不是
table_1 左连接 table_2 以table_1为基础进行连接运算,得到新表(#table)。
#table 右连接 table_3 以table_3为基础进行连接运算,得到最终结果。
搞不懂#table 右连接 table_3 ????


table_1 as a inner join table_2 as c
on
a.id=b.id 
这个语句得到一个新表为table


上面的语句相当于table inner join table_3 as c 是不是?

#10


我写的明明是left join 啊!

#11


第一个inner join 你可以把 table_1 看作 table_2 的左表 . 
然后第一个inner 完了后 会有一个临时表 
你可以把这个临时表看做 table_3 的左表.


table_1 left join table_2     table_1是table_2的左表
(table_1 left join table_2) a left join table_3 on a.???=table_3.???
a 是table_3的左表...

#12


说的好,我懂了,结贴!
nolast02(小明):多谢你的帮助谢谢,你指出我的错误,虽然你说了我有点迷!
Turkey119(火鸡):谢谢你,你的回答我有点懂,但是楼下哪们专业术语我一听就明白了!谢谢你
左右表很重要吗?
-->它阻碍了我的思维,你说重要不??
ojuju10(longdchuanren) :哥们偷赖了吧,没看我上面解释了么,不过谢谢你的指出!

welove1983() 说的比较好!'临时表' 这个专业术语用的真爽,我喜欢!
对了哥们给楼上几位来点分不建议吧!(*^_^*)

有空多多交流,有空来我的baidu空间玩,一起交流下!
http://hi.baidu.com/zhaofei299

#13


我在加一名.
right join 右表关联同理,只是位置不同!

#14


谢谢喽!

#15


错了 我的回答是错的...



左右表指的是 a.id=b.id 那么 a 就是 b的左表
a left join b on a.id=b.id left join c on a.id=c.id
a是b的左表 a是c的左表

a left join b on a.id=b.id left join c on b.id=c.id
a是b的左表 b是c的左表

#16


例如
create table a (tid int,name varchar(50))
insert into a select 1,'a'
insert into a select 2,'a'
insert into a select 3,'a'
insert into a select 4,'a'

select * from a ta full join (select * from a where tid=1) tb on ta.tid=tb.tid left join a tc on ta.tid=tc.tid

1 a 1 a 1 a
2 a NULL NULL 2 a
3 a NULL NULL 3 a
4 a NULL NULL 4 a

select * from a ta full join (select * from a where tid=1) tb on ta.tid=tb.tid left join a tc on tb.tid=tc.tid

1 a 1 a 1 a
2 a NULL NULL NULL NULL
3 a NULL NULL NULL NULL
4 a NULL NULL NULL NULL


#17


刚我想给分的时候,给不了,说什么贴了数超过了分数!郁闷!现在怎么搞?
本想上来说明情况,谁知道我连发3条不给发了!


这........我真不知道,现在怎么又错了?

你怎么又和我的第二种想法一样了?  迷惑不解中,请找点相关资料给我,谢谢!

#18


好象也不对... 我晕了....

#19


你是说,左右表关系是以on 的关联条件来决定??
而不是  关联的关键字左右来决定?

#20


晕了 等高人来...

#21


同等!哥们,你的bolg是多少?

#22


各位高手,各位牛人,回答问题的时候,如有相关资料请附了,谢谢!

#23


火鸡的回答是正确的,在查询里是把一个一个表不停地join进来组成一个很大的结果集,但组成结果集的同时,SQL还记得里面的每一个字段是从哪一个表来的,有时我们在join 的时候以表的名字或别名作为连接条件,主要原因还是不同的表可能有相同的字段,否则我们可以直接写字段的名字不用写表名

#24


不是以on 的关联条件来决定,是关联的关键字左右来决定的。

#25


table1 left join table2 和 table2 right join table1是等价的

#26


其实语句应该是这样的!
select * from 
table_1 as a left join table_2 as c
on
a.id=b.id 
left join table_3 as c
on
b.isbn=c.isbn 



.......................我有迷糊,也就是说,
Turkey119(火鸡) 
table_1 左连接 table_2 以table_1为基础进行连接运算,得到新表(#table)。
#table  左连接 table_3 以table#为基础进行连接运算,得到最终结果。


welove1983() 
第一个inner join 你可以把 table_1 看作 table_2 的左表 . 
然后第一个inner 完了后 会有一个临时表 
你可以把这个临时表看做 table_3 的左表.

--------------------------------------------
两个说法都正确喽!

应该就是这样吧!

#27


OK ,谢谢大家了!

#1


外连接才分吧

#2


還沒注意過,結果一致就好

#3


nolast02(小明)
不好意思写错了!真不对住啊!

left join
right join

#4


这个左右是相对的
只要理解外连接的实质就行了
table1 left join table2 和 table2 right join table1是等价的

#5


接分

#6


nolast02(小明)
谢谢,请再看下的问题!
select * from 
table_1 as a left join table_2 as c
on
a.id=b.id 
left join table_3 as c
on
b.isbn=c.isbn 

我想问的是在这个sql语句中左表是谁,右表又是谁,上面也写了我的疑问,
而不是left join 与right join 对比
请帮解答下!谢谢!

#7


楼主

table_1 左连接 table_2 以table_1为基础进行连接运算,得到新表(#table)。
#table 右连接 table_3 以table_3为基础进行连接运算,得到最终结果。

左右表很重要吗?

#8


楼主发的都是内连接,左右表的位置没有什么关系

#9


哦,有点懂了,你说的是不是
table_1 左连接 table_2 以table_1为基础进行连接运算,得到新表(#table)。
#table 右连接 table_3 以table_3为基础进行连接运算,得到最终结果。
搞不懂#table 右连接 table_3 ????


table_1 as a inner join table_2 as c
on
a.id=b.id 
这个语句得到一个新表为table


上面的语句相当于table inner join table_3 as c 是不是?

#10


我写的明明是left join 啊!

#11


第一个inner join 你可以把 table_1 看作 table_2 的左表 . 
然后第一个inner 完了后 会有一个临时表 
你可以把这个临时表看做 table_3 的左表.


table_1 left join table_2     table_1是table_2的左表
(table_1 left join table_2) a left join table_3 on a.???=table_3.???
a 是table_3的左表...

#12


说的好,我懂了,结贴!
nolast02(小明):多谢你的帮助谢谢,你指出我的错误,虽然你说了我有点迷!
Turkey119(火鸡):谢谢你,你的回答我有点懂,但是楼下哪们专业术语我一听就明白了!谢谢你
左右表很重要吗?
-->它阻碍了我的思维,你说重要不??
ojuju10(longdchuanren) :哥们偷赖了吧,没看我上面解释了么,不过谢谢你的指出!

welove1983() 说的比较好!'临时表' 这个专业术语用的真爽,我喜欢!
对了哥们给楼上几位来点分不建议吧!(*^_^*)

有空多多交流,有空来我的baidu空间玩,一起交流下!
http://hi.baidu.com/zhaofei299

#13


我在加一名.
right join 右表关联同理,只是位置不同!

#14


谢谢喽!

#15


错了 我的回答是错的...



左右表指的是 a.id=b.id 那么 a 就是 b的左表
a left join b on a.id=b.id left join c on a.id=c.id
a是b的左表 a是c的左表

a left join b on a.id=b.id left join c on b.id=c.id
a是b的左表 b是c的左表

#16


例如
create table a (tid int,name varchar(50))
insert into a select 1,'a'
insert into a select 2,'a'
insert into a select 3,'a'
insert into a select 4,'a'

select * from a ta full join (select * from a where tid=1) tb on ta.tid=tb.tid left join a tc on ta.tid=tc.tid

1 a 1 a 1 a
2 a NULL NULL 2 a
3 a NULL NULL 3 a
4 a NULL NULL 4 a

select * from a ta full join (select * from a where tid=1) tb on ta.tid=tb.tid left join a tc on tb.tid=tc.tid

1 a 1 a 1 a
2 a NULL NULL NULL NULL
3 a NULL NULL NULL NULL
4 a NULL NULL NULL NULL


#17


刚我想给分的时候,给不了,说什么贴了数超过了分数!郁闷!现在怎么搞?
本想上来说明情况,谁知道我连发3条不给发了!


这........我真不知道,现在怎么又错了?

你怎么又和我的第二种想法一样了?  迷惑不解中,请找点相关资料给我,谢谢!

#18


好象也不对... 我晕了....

#19


你是说,左右表关系是以on 的关联条件来决定??
而不是  关联的关键字左右来决定?

#20


晕了 等高人来...

#21


同等!哥们,你的bolg是多少?

#22


各位高手,各位牛人,回答问题的时候,如有相关资料请附了,谢谢!

#23


火鸡的回答是正确的,在查询里是把一个一个表不停地join进来组成一个很大的结果集,但组成结果集的同时,SQL还记得里面的每一个字段是从哪一个表来的,有时我们在join 的时候以表的名字或别名作为连接条件,主要原因还是不同的表可能有相同的字段,否则我们可以直接写字段的名字不用写表名

#24


不是以on 的关联条件来决定,是关联的关键字左右来决定的。

#25


table1 left join table2 和 table2 right join table1是等价的

#26


其实语句应该是这样的!
select * from 
table_1 as a left join table_2 as c
on
a.id=b.id 
left join table_3 as c
on
b.isbn=c.isbn 



.......................我有迷糊,也就是说,
Turkey119(火鸡) 
table_1 左连接 table_2 以table_1为基础进行连接运算,得到新表(#table)。
#table  左连接 table_3 以table#为基础进行连接运算,得到最终结果。


welove1983() 
第一个inner join 你可以把 table_1 看作 table_2 的左表 . 
然后第一个inner 完了后 会有一个临时表 
你可以把这个临时表看做 table_3 的左表.

--------------------------------------------
两个说法都正确喽!

应该就是这样吧!

#27


OK ,谢谢大家了!