UNION UNION-ALL
The UNION ALL
operator may be what you are looking for.
With this operator, you can concatenate the resultsets from multiple queries together, preserving all of the rows from each. Note that a UNION
operator (without the ALL
keyword) will eliminate any "duplicate" rows which exist in the resultset. The UNION ALL
operator preserves all of the rows from each query (and will likely perform better since it doesn't have the overhead of performing the duplicate check and removal operation).
The number of columns and data type of each column must match in each of the queries. If one of the queries has more columns than the other, we sometimes include dummy expressions in the other query to make the columns and datatypes "match". Often, it's helpful to include an expression (an extra column) in the SELECT list of each query that returns a literal, to reveal which of the queries was the "source" of the row.
SELECT 'q1' AS source, a, b, c, d FROM t1 WHERE ...
UNION ALL
SELECT 'q2', t2.fee, t2.fi, t2.fo, 'fum' FROM t2 JOIN t3 ON ...
UNION ALL
SELECT 'q3', '1', '2', buckle, my_shoe FROM t4
UNION UNION-ALL的更多相关文章
- sql inner join , left join, right join , union,union all 的用法和区别
Persons 表: Id_P LastName FirstName Address City 1 Adams John Oxford Street London 2 Bush George Fift ...
- mysql union ,UNION RESULT
mysql> explain select * from t100 union all select * from t200; +----+--------------+------------ ...
- ORACLE中union/union all/Intersect/Minus用法
Union,对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序: Union All,对两个结果集进行并集操作,包括重复行,不进行排序: Intersect,对两个结果集进行交集操作,不包 ...
- 数据库学习之五--Union, Union All和Intersect
一.定义 Union操作符用于合并两个或多个SELECT语句的结果集: 注:1. Union连接的Select语句之间必须拥有相同数量的列: 2. 列也必须拥有相似的数据类型: 3. 每条 SELEC ...
- PLSQL_基础系列03_合并操作UNION / UNION ALL / MINUS / INTERSET(案例)
2014-11-30 Created By BaoXinjian
- The difference between Union & Union All in SQL Server/pOSTGRESQL
Following is test in SQL Server: USE [TestDB] CREATE TABLE [dbo].[UserInfoTest02]( [number] [bigint] ...
- Oracle Union Union All 对查询结果集操作
在Oracle中提供了三种类型的集合操作: 并(UNION).交(INTERSECT).差(MINUS) Union:对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序: Union Al ...
- SQL中union union all 和in的查询效率问题
UNION用的比较多union all是直接连接,取到得是所有值,记录可能有重复 union 是取唯一值,记录没有重复 1.UNION 的语法如下: [SQL 语句 1] UNION [SQL 语句 ...
- sql中union,union all没有兼顾到的内容
今日遇到一个问题,两张表联合取交集去重,但是需要把某一字段相同的也给去掉 union all : 联合,没有取交集 union :联合取交集(仅针对所有字段相同的去重) 解决方案:将联合的数据作为一个 ...
- 集合操作符 Union / Union All / Intersect / Minus
集合操作符 Union / UnionAll / Intersect / Minus -- 生成测试数据 create table dept_01 as select * from dept wher ...
随机推荐
- 图解-Excel的csv格式特殊字符处理方式尝试笔记(个人拙笔)
Excel格式如下.(截图来自,WPS Office) CSV是一种文本格式的Excel文档格式.不支持Excel的字体特效(比如加粗,颜色)等等的保存. 每一行数据用 "\n" ...
- JFinal Template Engine 使用
官方文档:JFinal Template Engine 文档
- 聊聊、AES 和 DES
AES 和 DES 都是对称加密的一种,但是 DES 的 Key 是 56 位,而 AES 的 Key 有 128,256,512 可选. AES 加密AES String randomKey = & ...
- poj 1840 枚举
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 13967 Accepted: 6858 Description ...
- 第十四篇:JavaScript
本篇内容 简介 使用 DOM 一. 简介 JavaScript 是世界上最流行的编程语言. 这门语言可用于 HTML 和 web,更可广泛用于服务器.PC.笔记本电脑.平板电脑和智能手机等设备. Ja ...
- 【bzoj4952】[Wf2017]Need for Speed 二分
题目描述 已知$\sum\limits_{i=1}^n\frac{d_i}{s_i+c}=t$,求$c$ $(d_i>0,s_i+c>0)$ 输入 第一行包含两个整数n(1≤n≤1000) ...
- aFlex脚本入门
aFlex脚本入门 来源:http://blog.51cto.com/virtualadc/599194 来源:http://blog.51cto.com/virtualadc/624219 对于A1 ...
- LACP链路聚合控制协议
LACP链路聚合控制协议 来源: https://www.cnblogs.com/taosim/articles/4378691.html http://storage.chinabyte.com/6 ...
- 一文看懂Kafka消息格式的演变
摘要 对于一个成熟的消息中间件而言,消息格式不仅关系到功能维度的扩展,还牵涉到性能维度的优化.随着Kafka的迅猛发展,其消息格式也在不断的升级改进,从0.8.x版本开始到现在的1.1.x版本,Kaf ...
- Codeforces Round #421 (Div. 2) D. Mister B and PR Shifts
Codeforces Round #421 (Div. 2) D. Mister B and PR Shifts 题意:给一个长度为\(n\)的排列,每次可以向右循环移位一次,计算\(\sum_{i= ...