mysql左右连接

左连接即左表中的数据必须显示。
左/右连接查询实际上是指定以哪个表的数据为准。
有两个表:
table1
[table]
|id name password|
|1 aaa a|
|2 bbb b|
|3 ccc c|
[/table]
左连接sql语句:select table1.id,table1.name,table2.power from table1 left join table2 on table1.id = table2.id
得到如下结果:
table2
[table]
|id name power|
|1 aaa 000111|
|2 bbb 111000|
[/table]
右连接sql语句:select table1.id,table1.name,table2.power from table1 right join table2 on table1.id = table2.id
得到如下结果:
[table]
|id name power|
|1 aaa 000111|
|2 bbb 111000|
[/table]

左连接是只要左边的表中有记录,数据就能检索出来,而右边表中的记录必须在 左边表中有记录才能检索出来,如果右表中没有数据,将显示为null。

如下:table1如果为左连接中的左表,则左连接的查询结果会根据table1表中该数据的行数来显示。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值