# UNION

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [cloud-data-platform-full.txt](https://docs.redpanda.com/cloud-data-platform-full.txt)

---
title: UNION
latest-operator-version: v26.1.4
latest-console-tag: v3.7.3
latest-connect-version: 4.93.0
latest-redpanda-tag: v26.1.9
docname: sql/sql-clauses/set-operations/union
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: sql/sql-clauses/set-operations/union.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/reference/pages/sql/sql-clauses/set-operations/union.adoc
description: The UNION combines the result sets of two or more SELECT statements, removing duplicate rows between the tables.
page-topic-type: reference
page-git-created-date: "2026-05-26"
page-git-modified-date: "2026-05-26"
---

<!-- Source: https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-clauses/set-operations/union.md -->

`UNION` combines the result sets of two or more `SELECT` statements, removing duplicate rows between the tables.

## [](#syntax)Syntax

```sql
SELECT value1, value2, ... value_n
FROM table1
UNION
SELECT value1, value2, ... value_n
FROM table2;
```

Where:

-   `value1, value2, …​ value_n`: The columns to retrieve. You can also retrieve all columns using `SELECT * FROM`.

-   `table1, table2`: The tables to retrieve records from.


## [](#examples)Examples

Suppose there is a table called `employees` and another table called `contractors`. The goal is to retrieve a combined list of names from both tables, excluding duplicates:

```sql
CREATE TABLE employees (
    emp_id INT,
    emp_name TEXT
);

CREATE TABLE contractors (
    contractor_id INT,
    contractor_name TEXT
);

INSERT INTO employees VALUES
(1, 'John'),
(2, 'Alice'),
(3, 'Bob');

INSERT INTO contractors VALUES
(101, 'Alice'),
(102, 'Eve'),
(103, 'Tom');
```

Verify the inserted values:

```sql
SELECT * FROM employees;
SELECT * FROM contractors;
```

```sql
emp_id | emp_name
--------+----------
      1 | John
      2 | Alice
      3 | Bob

 contractor_id | contractor_name
---------------+-----------------
           101 | Alice
           102 | Eve
           103 | Tom
```

Combine the values from the tables:

```sql
SELECT emp_name FROM employees
UNION
SELECT contractor_name FROM contractors;
```

The query returns the values from both tables without duplicates:

```sql
emp_name
----------
 Alice
 Bob
 Eve
 John
 Tom
```

The duplicate name `Alice` appears only once in the output.

## [](#union-all)UNION ALL

`UNION ALL` combines the result sets of two or more `SELECT` statements, returning all rows from the queries without removing duplicates.

### [](#syntax-2)Syntax

```sql
SELECT value1, value2, ... value_n
FROM table1
UNION ALL
SELECT value1, value2, ... value_n
FROM table2;
```

Where:

-   `value1, value2, …​ value_n`: The columns to retrieve. You can also retrieve all columns using `SELECT * FROM`.

-   `table1, table2`: The tables to retrieve records from.


### [](#example)Example

Suppose you have two separate tables, `sales_2022` and `sales_2023`, containing sales data for different years. To combine the sales data from both tables without removing duplicates:

```sql
CREATE TABLE sales_2022 (
    transaction_id INT,
    product_name TEXT,
    sale_amount INT
);

CREATE TABLE sales_2023 (
    transaction_id INT,
    product_name TEXT,
    sale_amount INT
);

INSERT INTO sales_2022 VALUES
(1, 'Product A', 1000),
(2, 'Product B', 500),
(3, 'Product C', 750);

INSERT INTO sales_2023 VALUES
(4, 'Product A', 1200),
(5, 'Product D', 800),
(6, 'Product E', 950);
```

Verify the inserted values:

```sql
SELECT * FROM sales_2022;
SELECT * FROM sales_2023;
```

```sql
transaction_id | product_name | sale_amount
----------------+--------------+-------------
              1 | Product A    |        1000
              2 | Product B    |         500
              3 | Product C    |         750

 transaction_id | product_name | sale_amount
----------------+--------------+-------------
              4 | Product A    |        1200
              5 | Product D    |         800
              6 | Product E    |         950
```

Combine all values from the tables using `UNION ALL`:

```sql
SELECT product_name, sale_amount FROM sales_2022 UNION ALL SELECT product_name, sale_amount FROM sales_2023;
```

The query returns all rows from the first table followed by all rows from the second table, including duplicates:

```sql
product_name | sale_amount
--------------+-------------
 Product A    |        1000
 Product B    |         500
 Product C    |         750
 Product A    |        1200
 Product D    |         800
 Product E    |         950
```