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

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;
主站蜘蛛池模板: 桐柏县| 葫芦岛市| 博野县| 麦盖提县| 广平县| 容城县| 容城县| 梅州市| 垫江县| 兴和县| 通辽市| 石城县| 金昌市| 白山市| 富阳市| 尤溪县| 浦县| 博爱县| 光山县| 崇仁县| 凌云县| 平原县| 光山县| 长治市| 新巴尔虎左旗| 民乐县| 进贤县| 萨迦县| 郧西县| 游戏| 武穴市| 淮南市| 漠河县| 沧州市| 准格尔旗| 华容县| 新化县| 尚志市| 木里| 资源县| 庄浪县|