当前位置:   article > 正文

三表连接之内连接

三表内联

表之间的关系为:

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;

 

转载于:https://www.cnblogs.com/hzStudy/p/7286539.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/189022
推荐阅读
相关标签
  

闽ICP备14008679号