loading..
Русский    English
20:19

Cartesian product

The Cartesian product discussed previously is realized as a comma-separated list of table expressions (tables, views, subqueries) in the FROM clause where no join conditions are depicted in WHERE clause. In addition, another  explicit CROSS JOIN operation may be used: 

Console
Execute
  1. SELECT Laptop.model, Product.model
  2. FROM Laptop CROSS JOIN
  3. Product;

Recall that the Cartesian product combines each row in the first table with each row in the second table. The number of the rows in the result set is equal to the number of the rows in the first table multiplied by the number of the rows in the second table. In the example under consideration, the Laptop table has 5 rows while the Product table has 16 rows. As a result, we get 5*16 = 80 rows. Hence, there is no result set of that query here. You may check this assertion by clicking on the Execute link or by using Console.

Notes:

In the uncombined state, the Cartesian product is hardly used in practice. As a rule, it presents an intermediate restriction (horizontal projection) operation where the WHERE clause is available in the SELECT statement.

Suggested exercises: 58, 115

Tags
aggregate functions Airport ALL AND AS keyword ASCII AVG Battles Bezhaev Bismarck C.J.Date calculated columns Cartesian product CASE cast CHAR CHARINDEX Chebykin check constraint classes COALESCE common table expressions comparison predicates Computer firm CONSTRAINT CONVERT correlated subqueries COUNT CROSS APPLY CTE data type conversion data types database schema DATEADD DATEDIFF DATENAME DATEPART DATETIME date_time functions DDL DEFAULT DEFAULT VALUES DELETE DISTINCT DML duplicates edge equi-join EXCEPT exercise (-2) More tags
The book was updated
several days ago
продать райффайзен
©SQL-EX,2008 [Evolution] [Feedback] [About] [Links] [Team]
All right reserved.