数据库查询语句三

一 连接查询(JOIN)

1等值连接语法

select job,sal,comm,ioc from emp,dept where ename='SMIITH' and emp.deptno = dept.deptno;

2 外连接语法

假设emp表中有个全空的元素,它可以可任意元素匹配,满足连接条件,这样就是外连接

select ename,dept.deptno,Ioc from emp,dept wehre emp.deptno(+) =dept.deptno;

二 集合操作

包括UNION(集合并) INTERSECT集合交 MINUS集合差操作;

1 Union

select employee_name,age from development where age>35 union select employee_name,age from information where age>35;

2 intersect

select job from development intersect select job from informatio;

 

3 minus

select job from development minus select job from informatio;

三 子查询

1 多级子查询

select ename,deptno from emp where deptno=(select deptno from dept where ioc='BOSTON');

2 多个子查询语句

select ename,job,sal from emp where job =(select job from emp where ename ='CLARK') or sal>(select sal from emp where ename ='CLARK');

3 子查询有多个基表

select ename,job ,sal from emp ,dept where ioc='NEW WORK' and emp.deptno= dept.deptno and sal>(select sal from emp where ename='SCOTT');

4 子查询有聚合函数

select ename,hiredate from emp where hiredate=(select min(hiredate) from emp);

5 当子查询返回不止一个时,可以使用ALL ANY IN NOT IN

select ename,sal from emp where sal>any(select sal from emp where deptno=30) and deptno!=30;

6 当子查询返回值多于一个列时,主查询where 子句中的列名用括号括起来。

select ename,job,sal from emp where (job,sal) =(select job,sal from emp where ename='ford');

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值