交叉连接:返回笛卡尔积
语法:CROSS JOIN 表
例如:select * from emp CROSS JOIN dept;
自然连接:返回所有满足连接条件的值
语法:NATURAL JOIN 表
例如:select * from emp NATURAL JOIN dept;
USING:消除俩连接表的笛卡尔积
语法:JOIN 表 USING(关联列名称)
例如:select * from emp JOIN dept USING(deptno);
ON:自己写条件
语法:JOIN 表 ON(条件)
例如:select * from emp e JOIN salgrade s ON(e.sal BETWEEN s.losal AND s.hisal);
外连接:
语法:LEFT|RIGHT|FULL OUTER JOIN 表 ON(关联条件)
例如:select * from emp e LEFT OUTER JOIN dept d ON(e.deptno=d.deptno);
select * from emp e RIGHT OUTER JOIN dept d ON(e.deptno=d.deptno);
select * from emp e FULL OUTER JOIN dept d ON(e.deptno=d.deptno);
UNION并集:返回全部内容,重复元组不显示
例子:select * from dept UNION select * from dept where deptno=10;
UNION ALL并集:返回全部内容,重复元组显示
例子:select * from dept UNION ALL select * from dept where deptno=10;
注意:可以通过UNION或UNION ALL代替OR,且效率要高
如:select * from emp where job='SALESMAN' UNION select * from emp where job='CLERK';
MINUS差集:返回两个结果的差
例如:select * from dept MINUS select * from dept where deptno=10;
INTERSECT交集:返回两个结果的相交部分
例子:select * from dept INTERSECT select * from dept where deptno=10;