Skip to content
Exercises · Q14

Q.What is a cartesian product of two tables? If table A has 6 rows and table B has 3 rows, how many rows does their cartesian product have? How is an equi-join different from a plain cartesian product?

ChseodishaTextbookSubjectiveImportance★★★★★est
31% · 5/16 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

A cartesian product (also called a cross join) of two tables pairs every row of the first table with every row of the second, with no matching condition. It is produced by simply selecting from both tables:

SELECT * FROM Employee, Dept;

Number of rows: if table A has m rows and table B has n rows, the cartesian product has m x n rows. Here 6 x 3 = 18 rows. Most of these pairings are meaningless (for example, pairing a Sales employee with the Accounts department), which is why the plain cartesian product is rarely wanted on its own.

Difference from an equi-join: an equi-join takes the cartesian product and filters it, keeping only the paired rows in which the linking columns are equal (using the = operator) — typically matching a foreign key to a primary key:

SELECT Employee.Name, Dept.City
FROM Employee, Dept
WHERE Employee.Dept = Dept.DeptName;
``` …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.