Commit f0b5173
committed
feat(sql-joins): add explanation of Cartesian Product in SQL
What
- Documented the concept of Cartesian Product (CROSS JOIN) in SQL.
- Explained how it occurs when no join condition is provided.
- Illustrated with example tables (`Employees`, `Departments`) and resulting rows.
- Highlighted row count calculation: (rows in Table A × rows in Table B).
- Covered both intentional and unintentional use cases.
Why
- Helps differentiate between meaningful joins and accidental cross joins.
- Clarifies how missing `ON` conditions can lead to unexpected results.
- Provides awareness for developers working with SQL joins.
Key Points
- CROSS JOIN or missing ON condition → Cartesian Product.
- Useful for generating all possible combinations (e.g., customers × products).
- Avoid unintentional Cartesian Products by using:
- INNER JOIN
- LEFT JOIN
- RIGHT JOIN
with explicit `ON` conditions.
Real-life Applications
- Generating test datasets by pairing rows across tables.
- Recommendation engines (all users × all items).
- Scheduling systems (all employees × all time slots).
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent a0c4fa3 commit f0b5173
File tree
1 file changed
+5
-6
lines changed- Section28JDBCusingSQLite/JoinsInSQL
1 file changed
+5
-6
lines changedLines changed: 5 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
| 55 | + | |
57 | 56 | | |
58 | | - | |
| 57 | + | |
0 commit comments