- MySQL 8 for Big Data
- Shabbir Challawala Jaydip Lakhatariya Chintan Mehta Kandarp Patel
- 179字
- 2021-08-20 10:06:14
UNION
The UNION keyword is used to combine the results from multiple select queries into a single table. Each SELECT statement used in a UNION query must have the same number of columns and each column must require a similar data type. The column names from the first SELECT statement are used as the columns for the results returned.
For example, the Employee table:

For example, Contractor table:

The column names from the first SELECT statement are used as the columns for the results returned as shown in following example.
SELECT 'Employee' As Type, name, city, country FROM Employee
UNION
SELECT 'Contractor', name, city, country FROM Contractor;
The following example of UNION removes duplicate rows from the result; if we don't want to remove duplicate rows, the ALL keyword can be used:
SELECT country FROM Employee UNION SELECT country FROM Contractor;
This query returns two rows from the preceding table--Germany and Mexico. To fetch all rows from both these tables, we can use the ALL keyword as follows:
SELECT country FROM Employee UNION ALL SELECT country FROM Contractor;
- ASP.NET Core:Cloud-ready,Enterprise Web Application Development
- JavaScript前端開發(fā)模塊化教程
- 名師講壇:Java微服務(wù)架構(gòu)實(shí)戰(zhàn)(SpringBoot+SpringCloud+Docker+RabbitMQ)
- Unreal Engine 4 Shaders and Effects Cookbook
- VMware虛擬化技術(shù)
- Haskell Data Analysis Cookbook
- Python圖形化編程(微課版)
- Go語言底層原理剖析
- Image Processing with ImageJ
- 零基礎(chǔ)學(xué)Python編程(少兒趣味版)
- Visual FoxPro 6.0程序設(shè)計(jì)
- C++ System Programming Cookbook
- 跟戴銘學(xué)iOS編程:理順核心知識點(diǎn)
- Python Social Media Analytics
- 軟件設(shè)計(jì)模式(Java版)