Keep all rows from the left side even when no match exists.

Section: Querying, Joins, and Aggregation

Left join

sql
sql
SELECT c.customer_id, o.order_id
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.customer_id;
Explanation

See summary for usage details.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Querying, Joins, and Aggregation
Inner join
Combine matching rows from two tables.
OpenIn sheetsqlsame section
Basic SELECT
Fetch a sorted subset of rows.
OpenIn sheetsqlsame section
Use DISTINCT ON
Pick one row per group using PostgreSQL's `DISTINCT ON` extension.
OpenIn sheetsqlsame section
Group and filter aggregates
Aggregate rows and then filter groups.
OpenIn sheetsqlsame section
Window function row_number
Assign row numbers within each partition.
OpenIn sheetsqlsame section
Common table expression
Use a CTE to structure a multi-step query.
OpenIn sheetsqlsame section