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 ...
随机推荐
- CentOS6/7-防火墙管理
#CentOS6 #开放端口运行外部访问(不指定源IP) iptables -I INPUT -p tcp --dport -j ACCEPT iptables -I INPUT -p tcp --d ...
- kubeadm部署k8s1.9高可用集群--4部署master节点
部署master节点 kubernetes master 节点包含的组件: kube-apiserver kube-scheduler kube-controller-manager 本文档介绍部署一 ...
- 基于TensorFlow的循环神经网络(RNN)
RNN适用场景 循环神经网络(Recurrent Neural Network)适合处理和预测时序数据 RNN的特点 RNN的隐藏层之间的节点是有连接的,他的输入是输入层的输出向量.extend(上一 ...
- linux 出错 “INFO: task xxxxxx: 634 blocked for more than 120 seconds.”的3种解决方案(转)
linux 出错 “INFO: task xxxxxx: 634 blocked for more than 120 seconds.”的3种解决方案 1 问题描述 服务器内存满了,ssh登录失败 , ...
- jquery serialize() 方法
ajax异步提交的时候,会使用该方法. 方法:jQuery ajax - serialize() 方法
- 【Android】实验3 颜色、字符串资源的使用【提交截止时间:2016.4.1】
实验4 颜色.字符串资源的使用 [目的] 掌握Android中颜色和字符串资源的使用方法. 理解Android中尺寸和布局资源的使用方法. [要求] 在工程中为Activity.View使用颜色资源: ...
- 0-1背包问题(经典)HDU2602 Bone Collector
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- Linux命令之time
我使用过的Linux命令之time - 测定一个命令的资源使用情况 本文链接:http://codingstandards.iteye.com/blog/798788 (转载请注明出处) 用途说明 ...
- Tomcat的context.xml说明、Context标签讲解
Tomcat的context.xml说明.Context标签讲解 1. 在tomcat 5.5之前 --------------------------- Context体现在/conf/server ...
- lca板子
#include<cstdio> #include<cstring> #include<algorithm> #define LL long long using ...