PostgreSQL FULL JOIN

A FULL JOIN (or FULL OUTER JOIN) returns rows when there is a match in either table. It includes rows from both tables, filling non-matching columns with NULL.

Example

SELECT c.customer_id, o.order_id
FROM customers c
FULL JOIN orders o ON c.customer_id = o.customer_id;

Best Practices

  • Use FULL JOIN when you need all rows from both tables, regardless of matching.
  • Check for NULL values to distinguish unmatched rows from each table.

Key Takeaways

  • FULL JOIN includes every row from both tables.
  • Unmatched columns from either side are filled with NULL.