menu
Cross Join in PostgreSQL is like a full outer join, but without any matching condition. It simply combines every row from the first table with every row from the second table, creating a result set that is the product of the number of rows in both tables.

Example:

Let's say you have two tables:
  • Customers with columns customer_id and name
  • Products with columns product_id and name

A cross join between these two tables would produce a result set where every customer is paired with every product. This could be useful if you want to generate a list of all possible combinations of customers and products, perhaps for a recommendation system or a marketing campaign.

SELECT customers.customer_id, customers.name, products.product_id, products.name
FROM customers
CROSS JOIN products;

This query would create a table with a row for every combination of customer and product, showing each customer's ID and name along with each product's ID and name.