轻松上手,快乐学习!

SQL UNION, UNION ALL 关键字


UNION

UNION命令组合了两个或多个SELECT语句的结果集(仅限不同的值)

以下SQL语句从“Customers”和“Suppliers”表中返回城市(仅限不同的值):

实例

SELECT City FROM Customers
UNION
SELECT City FROM Suppliers
ORDER BY City;

运行实例»


UNION ALL

UNION ALL命令组合了两个或多个SELECT语句的结果集(允许重复值)。

以下SQL语句从“Customers”和“Suppliers”表中返回城市(允许重复值):

实例

SELECT City FROM Customers
UNION ALL
SELECT City FROM Suppliers
ORDER BY City;

运行实例»