PostgreSQL CROSS JOIN
A CROSS JOIN
returns the Cartesian product of two tables, combining each row of one table with every row of another. No ON
condition is used.
Example
SELECT c.customer_id, o.order_id
FROM customers c
CROSS JOIN orders o;
Best Practices
- Be cautious with large tables; a CROSS JOIN can produce massive result sets.
- Use CROSS JOIN only when you specifically need every combination of rows.
Key Takeaways
CROSS JOIN
pairs each row in the left table with each row in the right table.- No join condition is used, so the result is a Cartesian product.