1 交叉连接:不适用任何匹配条件。生成笛卡尔积
mysql> select * from employee,department; +----+------------+--------+------+--------+------+--------------+ | id | name | sex | age | dep_id | id | name | +----+------------+--------+------+--------+------+--------------+ | 1 | daxia | female | 18 | 200 | 200 | 技术 | | 1 | daxia | female | 18 | 200 | 201 | 人力资源 | | 1 | daxia | female | 18 | 200 | 202 | 销售 | | 1 | daxia | female | 18 | 200 | 203 | 运营 | | 2 | anwen | male | 48 | 201 | 200 | 技术 | | 2 | anwen | male | 48 | 201 | 201 | 人力资源 | | 2 | anwen | male | 48 | 201 | 202 | 销售 | | 2 | anwen | male | 48 | 201 | 203 | 运营 | | 3 | wudi | male | 38 | 201 | 200 | 技术 | | 3 | wudi | male | 38 | 201 | 201 | 人力资源 | | 3 | wudi | male | 38 | 201 | 202 | 销售 | | 3 | wudi | male | 38 | 201 | 203 | 运营 | | 4 | yage | female | 28 | 202 | 200 | 技术 | | 4 | yage | female | 28 | 202 | 201 | 人力资源 | | 4 | yage | female | 28 | 202 | 202 | 销售 | | 4 | yage | female | 28 | 202 | 203 | 运营 | | 5 | dafei | male | 18 | 200 | 200 | 技术 | | 5 | dafei | male | 18 | 200 | 201 | 人力资源 | | 5 | dafei | male | 18 | 200 | 202 | 销售 | | 5 | dafei | male | 18 | 200 | 203 | 运营 | | 6 | jingyu | female | 18 | 204 | 200 | 技术 | | 6 | jingyu | female | 18 | 204 | 201 | 人力资源 | | 6 | jingyu | female | 18 | 204 | 202 | 销售 | | 6 | jingyu | female | 18 | 204 | 203 | 运营 | +----+------------+--------+------+--------+------+--------------+2 内连接:只连接匹配的行
#找两张表共有的部分,相当于利用条件从笛卡尔积结果中筛选出了正确的结果 #department没有204这个部门,因而employee表中关于204这条员工信息没有匹配出来 mysql> select employee.id,employee.name,employee.age,employee.sex,department.name from employee inner join department on employee.dep_id=department.id; +----+-----------+------+--------+--------------+ | id | name | age | sex | name | +----+-----------+------+--------+--------------+ | 1 | daxia | 18 | female | 技术 | | 2 | anwen | 48 | male | 人力资源 | | 3 | wudi | 38 | male | 人力资源 | | 4 | yage | 28 | female | 销售 | | 5 | dafei | 18 | male | 技术 | +----+-----------+------+--------+--------------+ #上述sql等同于 mysql> select employee.id,employee.name,employee.age,employee.sex,department.name from employee,department where employee.dep_id=department.id;