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
相关文章
- Leetcode: Substring with Concatenation of All Words
- Get size of all tables in database
- Retargeting All Projects in a Solution to .NET 4.5.2
- What are all the possible values for HTTP “Content-Type” header?
- git fetch批处理,遍历一个文件夹下的所有子目录,执行git fetch --all
- python模块和包用法详解(__all__)
- async/await实现Promise.all()
- oracle函数 MAX([distinct|all]x)
- oralce函数 STDDEV([distinct|all]x)
- log4j的8个日志级别(OFF、FATAL、ERROR、WARN、INFO、DEBUG、TRACE、 ALL)
- 一个例子说明数据库union all的作用
- SQL Server-聚焦UNIOL ALL/UNION查询(二十三)
- SQL-Union、Union ALL合并两个或多个 SELECT 语句的结果集
- 浅析union/union all/distinct的区别和用途、distinct如何进行排序优化
- UNION搜索与UNION ALL的区别
- [LeetCode] 865. Smallest Subtree with all the Deepest Nodes 包含最深结点的最小子树
- [LeetCode] 863. All Nodes Distance K in Binary Tree 二叉树距离为K的所有结点
- Easy Way to Get All Dependent Library Names 快速获得所有依赖库名称
- 1087 All Roads Lead to Rome
- 847. Shortest Path Visiting All Nodes