易截截图软件、单文件、免安装、纯绿色、仅160KB

sql语句查询结果合并union all用法_数据库技巧

--合并重复行
select * from A
union
select * from B
--不合并重复行
select * from A
union all
select * from B
按某个字段排序
--合并重复行
select *
from (
select * from A
union
select * from B) AS T
order by 字段名
--不合并重复行
select *
from (
select * from A
union all
select * from B) AS T
order by 字段名
//sql server版
Select * from (
select top 2 id,adddate,title,url from bArticle where ClassId=1 order by adddate desc) A
Union All
Select * from (
select top 2 id,adddate,title,url from bArticle where ClassId=2 order by adddate desc) B
Union All
Select * from (
select top 2 id,adddate,title,url from bArticle where ClassId=3 order by adddate desc) C
Union All
Select * from (
select top 2 id,adddate,title,url from bArticle where ClassId=4 order by adddate desc) D
//mysql版
Select * from (
select id,adddate,title,url from bArticle where ClassId=1 order by adddate desc limit 0,2) A
Union All
Select * from (
select id,adddate,title,url from bArticle where ClassId=2 order by adddate desc limit 0,2) B
Union All
Select * from (
select id,adddate,title,url from bArticle where ClassId=3 order by adddate desc limit 0,2) C
Union All
Select * from (
select id,adddate,title,url from bArticle where ClassId=4 order by adddate desc limit 0,2) D
  


相关文档:

Oracle 学习:PL/SQL循序渐进全面学习教程

 课程四 组函数
  
  本课重点:
  1、了解可用的组函数
  2、说明每个组函数的使用方法
  3、使用GROUP BY
  4、通过HAVING来限制返回组
  注意:以下实例中标点均为英文半角
  一、概念:
  组函数是指按每组返回结果的函数。
  组函数可以出现在SELECT和HAVING 字段中。
  GROUP ......

Oracle 学习:PL/SQL循序渐进全面学习教程

  课程五 子查询
  
  本课重点:
  1、在条件未知的情况下采用嵌套子查询
  2、用子查询做数据处理
  3、子查询排序
  
  注意:以下实例中标点均为英文半角
  
  一、概述:
  子查询是一种SELECT句式中的高级特性,就是一个SELECT语句作为另一个语句的一个段。我们可以利用子查询来 ......

Oracle 学习:PL/SQL循序渐进全面学习教程

 课程九 声明变量
  
  本课重点:
  1、了解基本的PLSQL块和区域
  2、描述变量在PLSQL中的重要性
  3、区别PLSQL与非PLSQL变量
  4、声明变量
  5、执行PLSQL块
  
  注意:以下实例中标点均为英文半角
  
  一、概述:
  1、PLSQL 块结构:
  DECLARE --- 可选
  变量声 ......

SQL SERVERS数据整理

          今天星期天,因数据库太慢,最后决定将数据库进行重新整理.
(假定数据库名称为:DB_ste)
1、根据现在的数据库的脚本创建一个脚本文件(FILENAME:DB_ste.sql)
2、建立新的数据库DB_ste2,若有文件组的数据库,则需要建立相同的文件组。(DB_ste_Group)
3、将数据文 ......

一个稍微修改的SQL无限分级

前段时间  把之前的无限分级表稍微做了一些改进 改进后的表结构如下
ID  Name  ParentID ParentIDList  level
1    A          0             0-1   &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号