一、概述html
1.一、全部的join链接,均可以加上相似where a.id='1000'的条件,达到一样的效果。ide
1.二、除了cross join不能够加on外,其它join链接都必须加上on关键字,后均可加where条件。post
1.三、虽然均可以加where条件,可是他们只在标准链接的结果集上查找where条件。好比左外链接的结果没有class的三班,因此若是加 where class.id='C003'虽然在表中有,但在左链接结果集中没有,因此查询后,是没有记录的。url
二、实例,标准的join链接,(不加where条件的)spa
2.一、设有表以下:code
学生表htm
班级表,对应学生表中的classidblog
2.二、自链接:join ,inner joinget
1--自链接 :只返回两张表链接列的匹配项。2--如下三种查询结果同样。3select*from student s innerjoin class c on s.classid=c.id; 4select*from student s join class c on s.classid=c.id; 5select*from student s,class c where s.classid=c.id;
自链接结果:it
2.三、笛卡儿乘积:cross join
1--笛卡儿乘积链接 :即不加任何条件,达到 M*N 的结果集。
2--如下两种查询结果同样。
3select*from student s crossjoin class c;
4select*from student,class;
笛卡尔结果:
注意:若是cross join加上where s.classid=c.id条件,会产生跟自链接同样的结果:
1--加上条件,产生跟自链接同样的结果。2select*from student s crossjoin class c where s.classid=c.id;
自链接结果集的cross join链接结果
2.三、左外链接:left join
1--左链接 :列出左边表所有的,及右边表符合条件的,不符合条件的以空值代替。
2--在(+)计算时,哪一个带(+)哪一个须要条件符合的,另外一个所有的。即放左即右链接,放右即左链接。
3--如下结果集相同。
4select*from student s leftjoin class c on s.classid=c.id;
5select*from student s,class c where s.classid=c.id(+);
左链接结果:
2.四、右外链接:right join
1--右外链接 :与左链接同样,列出右边表所有的,及左边表符合条件的,不符合条件2--的用 空值 替代。3--(+)同样,它的位置与链接相反。4select*from student s rightjoin class c on s.classid=c.id; 5select*from student s,class c where s.classid(+)=c.id;
右链接结果
2.五、全链接:full join
1--全链接 :产生M+N的结果集,列出两表所有的,不符合条件的,以空值代替。
2select*from student s fulljoin class c on s.classid=c.id;
全链接结果集