一些概念回顾

来源:互联网 发布:演员高露的淘宝店 编辑:程序博客网 时间:2024/04/29 16:11
有两个表:
table1

id
name
password
1
aaa
a
2
bbb
b
3
ccc
c

 
table2

id
power
1
111000
2
000111

 
左连接sql语句:select table1.id,table1.name,table2.power from table1 left join table2 on table1.id = table2.id
得到如下结果:

id
name
power
1
aaa
000111
2
bbb
111000
3
ccc
(null)

 
右连接sql语句:select table1.id,table1.name,table2.power from table1 right join table2 on table1.id = table2.id
得到如下结果:

id
name
power
1
aaa
000111
2
bbb
111000

           
          左连接是只要左边的表中有记录,数据就能检索出来,而右边表中的记录必须在 左边表中有记录才能检索出来,如果右表中没有数据,将显示为null。
           如下:table1如果为左连接中的左表,则左连接的查询结果会根据table1表中该数据的行数来显示。

 

原创粉丝点击