一、外连接
外连接可分为:左连接、右连接、完全外连接。
1、左连接 left join 或 left outer join
左外连接包含left join左表所有行,如果左表中某行在右表没有匹配,则结果中对应行右表的部分全部为空(NULL).
例如:select * from student right join course on student.ID=course.ID
2、右连接 right join 或 right outer join
右外连接包含right join右表所有行,如果左表中某行在右表没有匹配,则结果中对应左表的部分全部为空(NULL)。
例如:select * from student full join course on student.ID=course.ID
3、完全外连接 full join 或 full outer join
完全外连接包含full join左右两表中所有的行,如果右表中某行在左表中没有匹配,则结果中对应行右表的部分全部为空(NULL),
如果左表中某行在右表中没有匹配,则结果 中对应行左表的部分全部为空(NULL)。
例如:select * from student full join course on student.ID=course.ID
二、内连接 join 或 inner join
inner join 是比较运算符,只返回符合条件的行。
例如:select * from student inner join course on student.ID=course.ID 此时相当于
select * from student,course where student.ID=course.ID
三、交叉连接 cross join
1.概念:没有 WHERE 子句的交叉联接将产生连接所涉及的表的笛卡尔积。第一个表的行数乘以第二个表的行数等于笛卡尔积结果集的大小。
例如:select * from student cross join course