SQL UNION ALL
2013-09-18 09:03
127 查看
QL UNION ALL is query that allows you to select related information from 2 tables, the result is different from the UNION statement. It return all the record from SELECT statement that used.
UNION ALL selects all rows from each table and combines them into a single table.
The syntax is as follows:
SELECT [COLUMN NAME 1], [COLUMN NAME 2],… FROM [TABLE NAME 1]
UNION ALL
SELECT [COLUMN NAME 1], [COLUMN NAME 2],… FROM [TABLE NAME 2]
EXAMPLE :
We have 2 table name GamesScores, GameScores_new.
Table GameScores
Table GameScores_new
SQL statement :
SELECT PlayerName FROM GameScores
UNION ALL
SELECT PlayerName FROM GameScores_new
Result:
UNION ALL selects all rows from each table and combines them into a single table.
The syntax is as follows:
SELECT [COLUMN NAME 1], [COLUMN NAME 2],… FROM [TABLE NAME 1]
UNION ALL
SELECT [COLUMN NAME 1], [COLUMN NAME 2],… FROM [TABLE NAME 2]
EXAMPLE :
We have 2 table name GamesScores, GameScores_new.
Table GameScores
PlayerName | Department | Scores |
Jason | IT | 3000 |
Irene | IT | 1500 |
Jane | Marketing | 1000 |
David | Marketing | 2500 |
Paul | HR | 2000 |
James | HR | 2000 |
PlayerName | Department | Scores |
Jason | IT | 3000 |
David | Marketing | 2500 |
Paul | HR | 2000 |
James | HR | 2000 |
SELECT PlayerName FROM GameScores
UNION ALL
SELECT PlayerName FROM GameScores_new
Result:
PlayerName |
Jason |
Irene |
Jane |
David |
Paul |
James |
Jason |
David |
Paul |
James |
相关文章推荐
- [Forward] SQL UNION ALL
- SQL UNION ALL和UNION
- LINQ体验(8)--LINQ to SQL语句之Union All/Union/Intersect和Top/Bottom和P...
- SQL 基础7—— 集合运算(UNION 与UNION ALL)
- SQL中的UNION和UNION ALL使用和介绍
- SQL 中的 UNION 和UNION ALL 的区别
- SQL指南 - UNION and UNION ALL
- UNION ALL实现的分级汇总示例.sql
- Part 9 Union and union all in sql server
- LINQ体验(8)——LINQ to SQL语句之Union All/Union/Intersect和Top/Bottom和Paging和SqlMethods
- 【SQL】SQL Union和SQL Union All 区别和使用
- SQL中的union和union all区别(转)
- LINQ体验(8)——LINQ to SQL语句之Union All/Union/Intersect和Top/Bottom和Paging和SqlMethods
- SQL UNION ALL的用法
- Etl之HiveSql调优(union all)
- mybatis中insert into ...select ...from dual union all select ... from dual 提示sql命令未结束的问题
- SQL 2000 UNION ALL 子查询增加排序列报错问题
- SQL Union和SQL Union All用法
- SQL 基础--> 集合运算(UNION 与UNION ALL)