PostgreSQL LEFT JOIN
A LEFT JOIN returns all rows from the left table, plus matching rows from the right table. Rows in the left table without matches in the right table still appear, but with NULLs for right table columns.
Example
SELECT c.customer_id, c.first_name, o.order_id
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id;
Best Practices
- Use
LEFT JOINwhen you must keep all rows from the left table, regardless of a match. - Check for
NULLvalues in the right table columns if you need to filter unmatched rows.
Key Takeaways
LEFT JOINincludes all rows from the left table.- Non-matching rows in the left table get
NULLvalues for right table columns.