---
schema_version: "1"
id: 890548b375ec4fae24f7ddaeaf3be3fdcb7e80be748c6cbd808a1a33b77a67b8
title: UNION, INTERSECT, and EXCEPT Operators
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-cloud/data-cloud-query-guide/references/data-cloud-sql-reference/sql-commands/select-union.md
canonical_url: https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/select-union.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 52195e78af2bcb3eb6654b42f82f07db75a3fdf1253b4431f8bc7bd92d80dd6f
products:
  - Data 360 Query Guide
  - Data 360 Developer Documentation
---
# `UNION`, `INTERSECT`, and `EXCEPT` Operators

By using the operators `UNION`, `INTERSECT`, and `EXCEPT`, the output of more than one `SELECT` statement can be combined to form a single result set. The `<select_statement>` can’t have an `ORDER BY` or `LIMIT` clause. `ORDER BY` and `LIMIT` can be attached to a sub-expression if it’s enclosed in parentheses. Without parentheses, these clauses apply to the result of the `UNION`.

The result of these operators, by default, doesn’t contain duplicates. To return duplicates in the result, specify the `ALL` option.

Operators in the same `SELECT` statement are evaluated from left to right. Intersect binds more tightly than `UNION` or `EXCEPT`. For example, `A UNION B INTERSECT C` is read as `A UNION (B INTERSECT C)`.

## `UNION`

The `UNION` operator computes the set union of the rows returned by the `SELECT` statements. A row is in the set union if it’s in at least one of the result sets. Provide two `SELECT` statements that produce the same number of columns, and have columns with compatible data types.

**Syntax**

```sql
<select_statement>
UNION [ ALL | DISTINCT ]
<select_statement>
```

## `INTERSECT`

The `INTERSECT` operator computes the set intersection of the rows returned by the `SELECT` statements. A row is in the intersection if it appears in both result sets. With the `ALL` option, a row that has `m` duplicates in the left table and `n` duplicates in the right table appears `min(m, n)` times in the result set.

**Syntax**

```sql
<select_statement>
INTERSECT [ ALL | DISTINCT ]
<select_statement>
```

## `EXCEPT`

The `EXCEPT` operator computes the set of rows that are in the result of the left `SELECT` statement but not in the result of the right one. With `ALL`, a row that has `m` duplicates in the left table and `n` duplicates in the right table appears `max(m - n, 0)` times in the result set.

**Syntax**

```sql
<select_statement>
EXCEPT [ ALL | DISTINCT ]
<select_statement>
```
