# RIGHT JOIN

> 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: RIGHT JOIN
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/from/right-join
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: sql/sql-clauses/from/right-join.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/reference/pages/sql/sql-clauses/from/right-join.adoc
description: The RIGHT JOIN returns all matching records from the right table combined with the left table.
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/from/right-join.md -->

The `RIGHT JOIN` returns all matching records from the right table combined with the left table. Even if there are no matching records in the left table, the `RIGHT JOIN` still returns a row in the result, with `NULL` in each column from the left table.

## [](#syntax)Syntax

```sql
SELECT column_1, column_2...
FROM table_1
RIGHT JOIN table_2
ON table_1.matching_field = table_2.matching_field;
```

In this syntax:

1.  `SELECT column_1, column_2…​` defines the columns from both tables to display.

2.  `FROM table_1` defines `table_1` as the left table in the `FROM` clause.

3.  `RIGHT JOIN table_2` defines `table_2` as the right table in the `RIGHT JOIN` condition.

4.  `ON table_1.matching_field = table_2.matching_field` sets the join condition after the `ON` keyword with the matching field between the two tables.


### [](#table-alias)Table alias

A table alias is a temporary name given to a table in a query. Aliases don’t change the result; they make queries easier to read.

```sql
SELECT A.column_1, B.column_2...
FROM table_1 A
RIGHT JOIN table_2 B
ON A.matching_field = B.matching_field;
```

## [](#examples)Examples

Create the `customer` table:

```sql
CREATE TABLE customer (
  id int NOT NULL,
  customer_name text
);

INSERT INTO customer
    (id, customer_name)
VALUES
    (201011,'James'),
    (200914,'Harry'),
    (201029,'Ellie'),
    (201925,'Mary');
```

```sql
SELECT * FROM customer;
```

This returns:

```sql
+-----------+----------------+
| id        | customer_name  |
+-----------+----------------+
| 201011    | James          |
| 200914    | Harry          |
| 201029    | Ellie          |
| 201925    | Mary           |
+-----------+----------------+
```

Create the `orders` table:

```sql
CREATE TABLE orders (
  order_id int NOT NULL,
  order_date date,
  order_amount int,
  customer_id int
);

INSERT INTO orders
    (order_id, order_date, order_amount, customer_id)
VALUES
    (181893,'2021-10-08',3000,201029),
    (181894,'2021-11-18',2000,201029),
    (181891,'2021-09-10',9000,201011),
    (181892,'2021-10-10',7000,201925),
    (181897,'2022-05-27',6700,null),
    (181899,'2021-07-22',4500,201011);
```

```sql
SELECT * FROM orders;
```

This returns:

```sql
+------------+------------------+---------------+-------------+
| order_id   | order_date       | order_amount  | customer_id |
+------------+------------------+---------------+-------------+
| 181893     | 2021-10-08       | 3000          | 201029      |
| 181894     | 2021-11-18       | 2000          | 201029      |
| 181891     | 2021-09-10       | 9000          | 201011      |
| 181892     | 2021-10-10       | 7000          | 201925      |
| 181897     | 2022-05-27       | 6700          | null        |
| 181899     | 2021-07-22       | 4500          | 201011      |
+------------+------------------+---------------+-------------+
```

A `RIGHT JOIN` query against these tables:

```sql
SELECT customer_name, order_date, order_amount
FROM customer
RIGHT JOIN orders
ON customer.id = orders.customer_id;
```

-   The `customer` table is the left table, and the `orders` table is the right table.

-   The query combines values from the `orders` table using `customer_id` and matches records using the `id` column from the `customer` table.

-   When records match, Redpanda SQL creates a new row with `customer_name` and `order_amount` columns as defined in the `SELECT` clause.

-   Otherwise, a new row is created with `NULL` values from the left table (`customer`).


The query returns:

```sql
+------------------+----------------+-----------------+
| customer_name    | order_date     | order_amount    |
+------------------+----------------+-----------------+
| James            | 2021-09-10     | 9000            |
| James            | 2021-07-22     | 4500            |
| Ellie            | 2021-10-08     | 3000            |
| Ellie            | 2021-11-18     | 2000            |
| Mary             | 2021-10-10     | 7000            |
| null             | 2022-05-27     | 6700            |
+------------------+----------------+-----------------+
```

Based on the data from the `customer` and `orders` tables:

-   Order id `181893` matches the customer `Ellie`.

-   Order id `181894` matches the customer `Ellie`.

-   Order id `181891` matches the customer `James`.

-   Order id `181899` matches the customer `James`.

-   Order id `181892` matches the customer `Mary`.

-   Order id `181897` does not match any customer, so the `customer_name` column is `NULL`.


> 📝 **NOTE**
>
> A `customer` can have zero or many `orders`. An item from `orders` belongs to zero or one `customer`.

The following Venn diagram illustrates the `RIGHT JOIN`:

![Venn diagram showing a right join between the Customer and Orders tables](https://docs.redpanda.com/cloud-data-platform/reference/_images/sql/right-join-venn.png)