Oracle 多表连接
select * from emp,dept;
select * from emp,dept where emp.deptno=dept.deptno;
select emp.*,dname,loc from where emp.deptno=dept.deptno;
select e.* ,dname,loc from emp e,dept d
  where e.deptno=d.deptno.
连接类型
Oracle 8i
select * from emp,dept
  where emp.deptno=dept.deptno and deptno=7499;
非等值连接
select empno,ename,sal,grade,losal,hisal from emp,salgrade
  where sal>=losal and sal<=hisal
左外连接
select * from emp,dept
  where emp.deptno(+)=dept.deptno
右外连接
select * from emp,dept
  where emp.deptno=dept.deptno(+)
自连接
select e1.empno,e1.ename,e1.mgr,e2.ename from emp e1,emp e2
  where e1.mgr=e2.empno and e1.empnto=7369
Oracle 9i
select * from emp cross join dept;
select * from emp natural join dept;(自动选择用那列连接)
select * from emp left outer join dept using(deptno);
select * from emp right outer join dept using(deptno);
select * from emp full outer join dept using(deptno);
select * from emp full outer join dept
  on(emp.deptno=dept.deptno);
多表连接
select emp_id,city_name,dept_name from locations l
  join departments d
  on(d.location_id=l.location_id)
  join employees e
  on(d.department_id=edepartment_id)
子查询
select * from emp
  where sal > (select avg(sal) from emp);
select sal from emp group by deptno,sal
  having sal > (select avg(sal) from emp);
select * from emp
  where sal in (select avg(sal) from group by deptno);
select * from emp
  where sal > any (select avg(sal) from group by deptno);
select * from emp
  where sal > all (select avg(sal) from group by deptno);
select * from emp where sal >
  (select max(a) from
    (select avg(sal) from group by deptno));