表之间的关系为:
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;
时间: 2024-10-10 05:59:02