数据表准备 学生表 和 课程表


内连接 join 或 innner join
筛选出满足条件的列,where也可以实现这种功能。
SELECT * FROM student JOIN course ON student.student_id = course.stu_id
结果

外连接
左外连接 left join 或者 left outer join
以第一个表为基础,第二个表找不到的项就设置为NULL。
SELECT * FROM student LEFT JOIN course ON student.student_id = course.stu_id
结果

右外连接 right join 或者 right outer join
以第二个表为基础,第一个表找不到的项就设置为NULL。
SELECT * FROM student RIGHT JOIN course ON student.student_id = course.stu_id
结果

全外连接 full join 或者 full outer join(SQL Server有,MYSQL没有全外连接)
左外连接+右外连接的结果。

交叉连接
表1的每一行都与表2的每一行拼接。(笛卡尔积)
SELECT * FROM student RIGHT JOIN course ON student.student_id = course.stu_id

参考链接
通俗易懂的join、left join、right join、full join、cross join


















