首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

mysql上下连接

2012-09-03 
mysql左右连接左连接即左表中的数据必须显示。左/右连接查询实际上是指定以哪个表的数据为准。有两个表: tab

mysql左右连接
左连接即左表中的数据必须显示。
         左/右连接查询实际上是指定以哪个表的数据为准。
有两个表:
table1
id    name    password1     aaa     a2     bbb     b3     ccc     c
左连接sql语句:select table1.id,table1.name,table2.power from table1 left join table2 on table1.id = table2.id
得到如下结果:
table2
id    name    power1     aaa     0001112     bbb     111000
右连接sql语句:select table1.id,table1.name,table2.power from table1 right join table2 on table1.id = table2.id
得到如下结果:
id    name    power1     aaa     0001112     bbb     111000
         
          左连接是只要左边的表中有记录,数据就能检索出来,而右边表中的记录必须在 左边表中有记录才能检索出来,如果右表中没有数据,将显示为null。

           如下:table1如果为左连接中的左表,则左连接的查询结果会根据table1表中该数据的行数来显示。

热点排行