码迷,mamicode.com
首页 > 其他好文 > 详细

三表连接之内连接

时间:2017-08-04 19:30:39      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:log   内连接   set   images   png   man   inner   技术   bsp   

表之间的关系为:

manager 1-------------->n department 1----------------->n employee


mysql> select * from manager;
技术分享

 


2 rows in set (0.00 sec)

mysql> select * from department;
技术分享

 


3 rows in set (0.00 sec)

mysql> select * from employee;
技术分享

 


2 rows in set (0.00 sec)

mysql> select * from manager as ma inner join department as de on ma.id=de.manag
er_id inner join employee as em on de.id=department_id;
技术分享

 


2 rows in set (0.02 sec)



三张表的连接可理解为这样:
mysql> select * from manager as ma inner join department as de on ma.id=de.manag
er_id;
技术分享

 


先让manager和department两张表做内连接,结果如上

然后再用这张表与employee做内连接。结果如下

mysql> select * from manager as ma inner join department as de on ma.id=de.manag
er_id inner join employee as em on de.id=department_id;
技术分享

 

三表连接之内连接

标签:log   内连接   set   images   png   man   inner   技术   bsp   

原文地址:http://www.cnblogs.com/hzStudy/p/7286539.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!