union与union all与order by
2014-04-29 17:42
411 查看
有时候我们会将两部分排序的结果联合起来显示,union会自动排序和去重,union all则不会
看以下sql语句:
select a,b,c from AA aa where ...... order by aa.a desc
union all
select a,b,c from BB bb where ...... order by bb.a desc
会报错,原因是union all 最后一个select才能orderby 或者就嵌套一层再order by,如下:
select * from (select a,b,c from AA aa where ...... order by aa.a desc)
union all
select * from (select a,b,c from BB bb where ...... order by bb.a desc)
看以下sql语句:
select a,b,c from AA aa where ...... order by aa.a desc
union all
select a,b,c from BB bb where ...... order by bb.a desc
会报错,原因是union all 最后一个select才能orderby 或者就嵌套一层再order by,如下:
select * from (select a,b,c from AA aa where ...... order by aa.a desc)
union all
select * from (select a,b,c from BB bb where ...... order by bb.a desc)
相关文章推荐
- framebuffer驱动开发三
- oracle数据库的静默状态
- Qt使用日记(1): 安装
- 只是做自己
- 【C++专题】static_cast, dynamic_cast, const_cast探讨
- framebuffer驱动开发二
- OpenCV中矩阵数据的访问(二)
- 【C++专题】static_cast, dynamic_cast, const_cast探讨
- uicollectionview 使用uibutton或者uiimageview实现旋转出现scale的问题
- c++指针
- jsonp跨域请求
- HDS相关(二)之具有Flash Access保护的HTTP Dynamic Streaming
- hdu 2999 sg函数(简单博弈)
- DELL Software contest 2014 C题 1002 Code Red
- ipv4理论知识1-ipv4介绍,ipv4记法,地址段个数算法
- UML-顺序图
- 从零学LINUX
- 不使用Cygwin,在eclipse中快速开发JNI,一键生成C头文件.h,以及一键使用NDK交叉编译
- 一个程序告诉你continue、return、break的区别,看过你就不会忘记!
- java多线程详解