1. 笛卡尔集
select * from emp, dept;
2. 等值连接
select ename, job from emp, dept
where emp.deptno=dept.deptno;
3. 非等值连接
select ename, grade from emp, salgrade
where sal between losal and hisal;
这个其实我不太明白到底是怎么弄的。前面的两种都容易理解,这个难道是
拿一个sal就去salgrade中找在哪个范围?
4. 自连接
select t1.empno, t1.ename, t2.empno, t2.ename
from emp t1, emp t2
where t1.mgr=t2.empno;
5. 左外连接
select t1.empno, t1.ename, t2.dname
from emp t1, dept t2
where t1.deptno=t2.deptno(+);
select empno, ename, dname
from emp left outer join dept on emp.deptno=dept.deptno;
http://www.tuicool.com/articles/eQ3uiu
这篇文章介绍的还是挺详细的,基本上明白这些连接是怎么个意思了。
6. 右外连接
select t1.empno, t1.ename, t2.dname
from emp t1, dept t2
where t1.deptno(+)=t2.deptno;
select empno, ename, dname
from emp right outer join dept on emp.deptno=dept.deptno;
7. 满外连接
select empno, ename, dname
from emp full outer join dept on emp.deptno=dept.deptno;