

# Joins

A join combines each row of one source with the rows of another source that meet the join condition. The `[ INNER ] JOIN` form returns only the pairs of rows that match. `LEFT [ OUTER ] JOIN` also returns each row of the left source that has no match, with `NULL` in the columns of the right source. `RIGHT [ OUTER ] JOIN` does the same for the right source, and `FULL [ OUTER ] JOIN` for both. `CROSS JOIN` pairs every row of one source with every row of the other and takes no condition.

Give the condition with `ON` `condition`, or with `USING (``columns``)` when both sources have columns of the same name that must be equal. With `USING`, the result has one column for each join column, and with a full outer join that column holds the value from whichever side has one. `NATURAL JOIN` joins on every column name that the two sources share.

DuckDB also supports `SEMI`, `ANTI`, `LATERAL`, `ASOF`, and `POSITIONAL` joins. For more information about these joins, see [`SEMI` and `ANTI` joins](duckdb-statement-select-semi-anti-joins.md), [`LATERAL` joins](duckdb-statement-select-lateral-joins.md), [`ASOF` joins](duckdb-statement-select-asof-joins.md), and [`POSITIONAL` joins](duckdb-statement-select-positional-joins.md).

## Syntax
<a name="athena-duckdb-statement-select-joins-syntax"></a>

```sql
{{from_item}} [ INNER | LEFT [ OUTER ] | RIGHT
    [ OUTER ] | FULL [ OUTER ] ] JOIN {{from_item}}
    { ON {{condition}} | USING ( {{column}} [, ...] ) }
{{from_item}} NATURAL [ INNER | LEFT [ OUTER ] | RIGHT
    [ OUTER ] | FULL [ OUTER ] ] JOIN {{from_item}}
{{from_item}} CROSS JOIN {{from_item}}
```

## Examples
<a name="athena-duckdb-statement-select-joins-examples"></a>

For a description of the sample tables that the examples on this page use, see [SELECT statement in DuckDB](duckdb-statement-select.md).

The following SQL query joins each order to the manager of its region. The `north` region has no manager, so its order is left out.

```sql
SELECT s.order_id, s.customer, m.manager
FROM sales_db.sales_parquet AS s
JOIN (VALUES
    ('east', 'maria'),
    ('west', 'wei')
) AS m(region, manager)
  ON s.region = m.region
ORDER BY s.order_id
```

The query returns the following results.


| order\_id | customer | manager | 
| --- | --- | --- | 
| `1` | `alice` | `maria` | 
| `2` | `bob` | `wei` | 
| `3` | `carol` | `maria` | 
| `5` | `erin` | `wei` | 
| `6` | `frank` | `maria` | 

The following SQL query uses a left outer join, so the order in the `north` region is kept with a `NULL` manager.

```sql
SELECT s.order_id, s.customer, m.manager
FROM sales_db.sales_parquet AS s
LEFT JOIN (VALUES
    ('east', 'maria'),
    ('west', 'wei')
) AS m(region, manager)
  ON s.region = m.region
ORDER BY s.order_id
```

The query returns the following results.


| order\_id | customer | manager | 
| --- | --- | --- | 
| `1` | `alice` | `maria` | 
| `2` | `bob` | `wei` | 
| `3` | `carol` | `maria` | 
| `4` | `dave` | `NULL` | 
| `5` | `erin` | `wei` | 
| `6` | `frank` | `maria` | 

The following SQL query uses a full outer join with `USING`. The `region` column holds the value from whichever side has one, including the `south` region, which has a manager and no orders.

```sql
SELECT region, s.order_id, m.manager
FROM (
    SELECT
        *
        FROM sales_db.sales_parquet WHERE order_id <= 2
) AS s
FULL OUTER JOIN (VALUES
    ('east', 'maria'),
    ('south', 'li')
) AS m(region, manager)
  USING (region)
ORDER BY region
```

The query returns the following results.


| region | order\_id | manager | 
| --- | --- | --- | 
| `east` | `1` | `maria` | 
| `south` | `NULL` | `li` | 
| `west` | `2` | `NULL` | 

The following SQL query pairs every size with every color.

```sql
SELECT s.size, c.color
FROM (VALUES ('S'), ('M')) AS s(size)
CROSS JOIN (VALUES ('red'), ('blue')) AS c(color)
ORDER BY s.size, c.color
```

The query returns the following results.


| size | color | 
| --- | --- | 
| `M` | `blue` | 
| `M` | `red` | 
| `S` | `blue` | 
| `S` | `red` | 