The SQL CROSS JOIN returns the Cartesian product of two tables, meaning it combines each row of the first table with each row of the second table.
Consider two tables, Products and Customers, with columns as follows:
- Products: ProductID, ProductName
- Customers: CustomerID,
CustomerName
We want to retrieve all possible combinations of products and customers.
SELECT Products.ProductID,
Products.ProductName, Customers.CustomerID, Customers.CustomerName FROM Products CROSS JOIN Customers;
In this example, the CROSS JOIN combines each row from the Products
table with each row from the Customers
table, resulting in a Cartesian product.
This means that every product will be paired with every customer. The result
set will contain columns from both tables, showing all possible combinations of
products and customers.
Comments
Post a Comment