三表连接之内连接

Posted 长大当个科学家

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了三表连接之内连接相关的知识,希望对你有一定的参考价值。

表之间的关系为:

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;

 

以上是关于三表连接之内连接的主要内容,如果未能解决你的问题,请参考以下文章

查询无重合三表连接

三表连接 MySQL

MySQL 三表链式左连接,按最后一个表过滤

sql多表链接之三表连接查询

MySQL多表查询 三表查询 连接查询的套路

MySql的join(连接)查询 (三表 left join 写法)