二个表连接
mysql> select employee.first_name, job.title, duty.task
-> from employee, job, duty
-> where (employee.id = job.id and employee.id = duty.id);
+------------+------------+-----------+
| first_name | title | task |
+------------+------------+-----------+
| jason | tester | test |
| alison | accountant | calculate |
| james | developer | program |
| celia | coder | test |
| robert | director | manage |
| linda | mediator | talk |
| david | proffessor | speak |
| james | programmer | shout |
+------------+------------+-----------+
8 rows in set (0.00 sec)
mysql>
mysql>
mysql>
mysql> drop table duty;
query ok, 0 rows affected (0.00 sec)
mysql> drop table job;
query ok, 0 rows affected (0.01 sec)
mysql> drop table employee;
query ok, 0 rows affected (0.00 sec)
总结
inner join 连接两个数据表的用法:
select * from 表1 inner join 表2 on 表1.字段号=表2.字段号
inner join 连接三个数据表的用法:
select * from (表1 inner join 表2 on 表1.字段号=表2.字段号) inner join 表3 on 表1.字段号=表3.字段号
inner join 连接四个数据表的用法:
select * from ((表1 inner join 表2 on 表1.字段号=表2.字段号) inner join 表3 on 表1.字段号=表3.字段号) inner join 表4 on member.字段号=表4.字段号
inner join 连接五个数据表的用法:
select * from (((表1 inner join 表2 on 表1.字段号=表2.字段号) inner join 表3 on 表1.字段号=表3.字段号) inner join 表4 on member.字段号=表4.字段号) inner join 表5 on member.字段号=表5.字段号