Table 1
FirstName LastName John Smith Bob Dylan Alice Somers Jacob Hobbs
Table 2
FirstName LastName John Smith Bob Dylan Alice Somers
What does the Cartesian product of the two tables represent in SQL?
Table 1
| FirstName | LastName |
|---|---|
| John | Smith |
| Bob | Dylan |
| Alice | Somers |
| Jacob | Hobbs |
Table 2
| FirstName | LastName |
|---|---|
| John | Smith |
| Bob | Dylan |
| Alice | Somers |
What does the Cartesian product of the two tables represent in SQL?
Solution
The Cartesian product pairs every row of Table 1 with every row of Table 2, so the number of rows in the result is the product of the two row counts.
Table 1 has 4 rows and Table 2 has 3 rows, so the result has rows.
Options 1 and 2: INTERSECTION and UNION keep rows as they are (common rows, or all rows stacked), while a Cartesian product joins rows from both tables side by side.
We believe the answer could be Option 3, since it directly describes the Cartesian product (each row of Table 1 combined with all rows of Table 2), while Option 4 only gives the row count of the result. However, NTA's final answer key (after all challenges) says Option 4.
Related questions:
2025: 14 May Shift 1
2025: 30 May Shift 2
2025: 27 May Shift 2