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的更多相关文章

  1. 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 ...

  2. mysql union ,UNION RESULT

    mysql> explain select * from t100 union all select * from t200; +----+--------------+------------ ...

  3. ORACLE中union/union all/Intersect/Minus用法

    Union,对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序: Union All,对两个结果集进行并集操作,包括重复行,不进行排序: Intersect,对两个结果集进行交集操作,不包 ...

  4. 数据库学习之五--Union, Union All和Intersect

    一.定义 Union操作符用于合并两个或多个SELECT语句的结果集: 注:1. Union连接的Select语句之间必须拥有相同数量的列: 2. 列也必须拥有相似的数据类型: 3. 每条 SELEC ...

  5. PLSQL_基础系列03_合并操作UNION / UNION ALL / MINUS / INTERSET(案例)

    2014-11-30 Created By BaoXinjian

  6. The difference between Union & Union All in SQL Server/pOSTGRESQL

    Following is test in SQL Server: USE [TestDB] CREATE TABLE [dbo].[UserInfoTest02]( [number] [bigint] ...

  7. Oracle Union Union All 对查询结果集操作

    在Oracle中提供了三种类型的集合操作: 并(UNION).交(INTERSECT).差(MINUS) Union:对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序: Union Al ...

  8. SQL中union union all 和in的查询效率问题

    UNION用的比较多union all是直接连接,取到得是所有值,记录可能有重复 union 是取唯一值,记录没有重复 1.UNION 的语法如下: [SQL 语句 1] UNION [SQL 语句 ...

  9. sql中union,union all没有兼顾到的内容

    今日遇到一个问题,两张表联合取交集去重,但是需要把某一字段相同的也给去掉 union all : 联合,没有取交集 union :联合取交集(仅针对所有字段相同的去重) 解决方案:将联合的数据作为一个 ...

  10. 集合操作符 Union / Union All / Intersect / Minus

    集合操作符 Union / UnionAll / Intersect / Minus -- 生成测试数据 create table dept_01 as select * from dept wher ...

随机推荐

  1. 如何创造财富?硅谷创业之父 Paul Graham 《黑客与画家》思维导图

    先送上亚马逊传送门:<黑客与画家>:硅谷创业之父 Paul Graham 文集 再送上一个思维导图: 下载大图:http://caifujianghu.com/article/ruhe-c ...

  2. sweetalert : 一个比较好看的弹出框

    1.引入 <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"> </script& ...

  3. 每天一个Linux命令(1):cd命令

    cd命令用来切换工作目录至dirName,其中dirName表示绝对路径或相对路径.若目录名称省略,则切换至使用者的home directory(也就是钢login时所在的目录).另外,~ 也表示ho ...

  4. Python 协程与事件循环

    Table of Contents 前言 协程 async & await 事件循环 asyncio 的事件循环 结语 参考链接 前言 Python 标准库 asyncio 是我目前接触过的最 ...

  5. SQL面试题:之一(难度:中等)

    SQL面试题:之一(难度:中等)

  6. flask_入门教程之一

    一.教程涉及开发语言.脚本.框架.数据库等内容 Python + Flask + requests 通过命令安装:pip install flask 二.创建第一个flask脚本 一个最小的 Flas ...

  7. Search Engine —— Regular Expression(Spider)

    Regular Expression,即正则表达式:用来查找符合某些负责规则的字符串的需要.它真是用于描述这些规则的工具. 1. \b 是一个元字符,用来匹配一个位置,代表着单词的开头或结尾,也就是单 ...

  8. Codeforces Round #389 (Div. 2) 752E(二分答案)

    题目大意 可以理解成有n个木板,可以选取木板将其劈成2半(如果长度是奇数,就切成x和x+1),切完之后还可以再切 然后你要把这n个木板切成更多的木板,然后从中选择k个,使得这k个木板的最小长度尽量大 ...

  9. 转 android Listview,gridview局部刷新,部分刷新 (仿QQ动态评论局部刷新)

    转自:http://blog.csdn.net/jdsjlzx/article/details/45582719 众所周知Listview和Gridview的刷新界面的方式是调用adapter.not ...

  10. 洛谷T8116 密码

    T8116 密码 题目描述 YJC把核弹发射密码忘掉了……其实是密码被加密了,但是YJC不会解密.密码由n个数字组成,第i个数字被加密成了如下形式:第k小的满足(2^L)|(P-1)且P为质数的P.Y ...