多表查询
消除笛卡尔积的多表查询(内连接)
- 将员工表与工资等级表连接(条件是工资范围)
select e.empno 编号,
e.ename 姓名,
e.hiredate 雇佣日期,
e.sal 基本工资,
decode(g.grade,'1','E等工资',
'2','D等工资',
'3','C等工资',
'4','B等工资',
'5','A等工资') as 工资等级
from emp e,salgrade g where sal between g.losal and g.hisal;
- 查询姓名,职位,基本工资,部门名称和工资等级(三张表的连接)
select e.ename 姓名,e.job 职位,e.sal 基本工资,d.dname 部门名称,
decode(sg.grade,'1','E等工资',
'2','D等工资',
'3','C等工资',
'4','B等工资',
'5','A等工资') as 工资等级
from emp e,dept d,salgrade sg
where e.deptno = d.deptno and sal between sg.losal and sg.hisal;
插入数据后,需要commit
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno)
values(8888,'小李','CLERK',7369,sysdate,8000,250,20);
commit;
外连接:通过关联列(+)决定使用的是左还是右外连接
- (+)在表2的关联字段上则显示表1的所有数据