---
schema_version: "1"
id: 7e339cad2aef349c133de2b7a159943e71932d2fd0b706e7e4c41c15c7e963b8
title: UNION Operator
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_sql/guides/bi-sql-union.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-sql/guide/bi-sql-union.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 3772b0b33b306b8181febba7c7bd57f7a3e37a15a5e600151f5e08f412c9db2c
products:
  - SQL for Analytics Developer Guide
  - analytics
---

# UNION Operator

Use the `UNION` operator to combine the results of two or more `SELECT` statements. The joined statements must have the same number of columns and the same data types for corresponding columns.

SQL for CRM Analytics supports `UNION ALL` only. This clause returns all results—it doesn't remove duplicate values. Let's see what happens when we combine two `SELECT` statements that retrieve the `Cities` field.

```nolang
SELECT City From "Superstore" UNION ALL SELECT City from "Superstore";
```

The query returns all `City` results in an unspecified order.

| City            |
| --------------- |
| Henderson       |
| Henderson       |
| Los Angeles     |
| Fort Lauderdale |
| Fort Lauderdale |
| Los Angeles     |
| Los Angeles     |
| Los Angeles     |
| Los Angeles     |
| Los Angeles     |

To include an `ORDER BY` or `LIMIT` clause when using the `UNION` operator, you must enclose the first `SELECT` statement in parentheses so that the SQL parser can identify the `UNION` operator.

In this example, `ORDER BY City DESC` applies to the results of the full query, not only the second `SELECT` clause. The results display in reverse alphabetical order for the combined set of the `City` field.

```nolang
(SELECT City
FROM "Superstore"
ORDER BY City ASC)
UNION ALL
SELECT City
FROM "Superstore"
ORDER BY City DESC;
```

| City    |
| ------- |
| Yuma    |
| Yuma    |
| Yuma    |
| Yuma    |
| Yuma    |
| Yuma    |
| Yuma    |
| Yuma    |
| Yucaipa |
| Yucaipa |
| York    |

If you include parentheses around the second `SELECT` statement, the query returns results from the first `SELECT` statement in ascending order and the second in descending order.

```nolang
(SELECT City
FROM "Superstore"
ORDER BY City ASC)
UNION ALL
(SELECT City
FROM "Superstore"
ORDER BY City DESC);
```

The first ten results show values from the first `SELECT` statement in ascending order.

| City     |
| -------- |
| Aberdeen |
| Abilene  |
| Akron    |
| Akron    |
| Akron    |
| Akron    |
| Akron    |
| Akron    |
| Akron    |
| Akron    |
