官术网_书友最值得收藏!

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;
主站蜘蛛池模板: 林周县| 西乌珠穆沁旗| 葵青区| 宣恩县| 武冈市| 昌宁县| 防城港市| 辽阳县| 炉霍县| 广平县| 建湖县| 自贡市| 卢龙县| 江孜县| 新蔡县| 临西县| 仁化县| 涞源县| 龙井市| 布尔津县| 郴州市| 乐陵市| 荣成市| 恩施市| 陆良县| 乐亭县| 天气| 当涂县| 乐陵市| 梁山县| 垦利县| 渝中区| 镇雄县| 韶关市| 柳林县| 丰原市| 武胜县| 雅安市| 白朗县| 江油市| 鹤峰县|