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 ...
随机推荐
- 社区版pycharm安装Django框架
1.cmd下执行:pip3 install django 2.cmd下执行:django-admin startproject Demo (Demo为项目名称,可以更改你取的项目名称) 3.cmd下执 ...
- Python 自学 Day1
作业二:编写登陆接口 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 #!/usr/bin/env python import getpass def log(): uname = input ...
- [g2o]C++图优化库
g2o以图模型表达上述最小二乘问题:比较适合解决SLAM问题 http://openslam.org http://wiki.ros.org/g2o
- STL之算法使用简介
accumlate : iterator 对标志的序列中的元素之和,加到一个由 init 指定的初始值上.重载的版本不再做加法,而是传进来的二元操作符被应用到元素上. adjacent_differ ...
- hadoop 客户的的使用
${HADOOP_HOME}/bin/hadoop job Usage: JobClient <command> <args> [-submit <job-file> ...
- 软工实践Alpha冲刺(6/10)
队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 已经解决登录注册等基本功能的界面. 完成了主界面的基本布局 ...
- android自定义控件属性
有两种方法为自定义的控件设置属性 . 来自为知笔记(Wiz)
- HDU 1532 基础EK Drainage Ditches
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- ocrosoft Contest1316 - 信奥编程之路~~~~~第三关 问题 M: 当总统
http://acm.ocrosoft.com/problem.php?cid=1316&pid=12 题目描述 小明想当丑国的总统,丑国大选是按各州的投票结果来确定最终的结果的,如果得到超过 ...
- 【DNS】- 域名解析中A记录、CNAME、MX记录、NS记录的区别和联系
1. A记录 又称IP指向,用户可以在此设置子域名并指向到自己的目标主机地址上,从而实现通过域名找到服务器.说明:·指向的目标主机地址类型只能使用IP地址: 附加说明: 1) 泛域名解析即将该域名所有 ...