常用SQL
来源:互联网 发布:淘宝里的旺旺号是什么 编辑:程序博客网 时间:2024/04/30 13:42
查询:
select ... from ... where ... group by ... having ...;
左连接右连接全连接
left join、 right join、 full join、 inner join 内连接、等值连接
若A有10条数据,B中有15条数据,AB中公共数据有5条
select * from A left join B on ... 结果为10条数据
select * from A right join B on ... 结果为15条数据
select * from A full join B on ... 结果为20条数据
select * from A inner join B on ... 结果为5条数据
exists 与 in
exists用检查子检查的返回值为true或false。
例:select * from A where exists ( select null ) 等价于 select * from A
select * from A where exists (select B.the_id from B where the_id=A.the_id)
select * from A where the_id in (select distinct(the_id) from B)
in只能判断一列,且exists的效率一般比in高,因为in不走索引
isnull(列名,替换字符串)
case when 列名=‘’ then '空' else '非空' end
union 与 union all
A中10条记录,B中15条记录,5条重复记录
select a,b,c from table_A
union
select a,b,c from tbale_B
union默认删除重复记录,所以结果为20条记录
select a,b,c from table_A
union all
select a,b,c from table_B
直接连接两个查询结果,共25条记录
0 0
- 常用sql
- 常用sql
- 常用SQL
- 常用SQL
- 常用sql
- 常用SQL
- sql常用
- SQL常用
- 常用SQL
- 常用sql
- 常用SQL
- 常用SQL
- 常用SQL
- sql 常用
- 常用Sql
- 常用sql
- sql常用
- 常用SQL
- Makefile以及链接库
- [tcpip] 准备工作
- 机器视觉:OpenCV+VS2012+四轴+WIFI+物体跟踪
- 客户端网页编程--第二章(部分)、第三章
- SQL Incorrect syntax near 错误
- 常用SQL
- window基本知识
- android适配浅析
- 防火墙问题
- 通过“分布式系统的8大谬误”反思APP的设计 第六篇 谬误6:只有一个管理者
- 【搜索】 HDU 5323 Solve this interesting problem
- java学习笔记(六) collections--stack
- html基础2
- 55. Jump Game