You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Added the outer join
* Update joins.md
* Update joins.md
* Refactor example tables in joins.md for clarity
Updated the example tables in the joins section to remove HTML entities and improve readability.
* Format fix
Copy file name to clipboardExpand all lines: content/sql/concepts/joins/joins.md
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,6 +40,40 @@ An `OUTER JOIN` will combine rows from different tables even if the join conditi
40
40
-[`RIGHT JOIN`](https://www.codecademy.com/resources/docs/sql/commands/right-join), which combines matches with all rows from the right-side table.
41
41
-[`FULL OUTER JOIN`](https://www.codecademy.com/resources/docs/sql/commands/full-outer-join), which combines matches with all rows from the left- and right-side tables.
42
42
43
+
## CROSS JOIN
44
+
45
+
A `CROSS JOIN` clause combines each row from one table with each row from another in the result set. This result is also known as a `Cartesian product`. The following query returns every combination of `shirt_color` and `pants_color`:
46
+
47
+
```sql
48
+
SELECTshirts.shirt_color,
49
+
pants.pants_color
50
+
FROM shirts
51
+
CROSS JOIN pants;
52
+
```
53
+
54
+
For example, here's the `shirts` table:
55
+
56
+
| shirt_color |
57
+
| ----------- |
58
+
| white |
59
+
| grey |
60
+
61
+
And the `pants` table:
62
+
63
+
| pants_color |
64
+
| ----------- |
65
+
| light |
66
+
| dark |
67
+
68
+
The result of the query would contain every combination of the two tables:
69
+
70
+
| shirt_color | pants_color |
71
+
| ----------- | ----------- |
72
+
| white | light |
73
+
| white | dark |
74
+
| grey | light |
75
+
| grey | dark |
76
+
43
77
## UNION
44
78
45
79
The [`UNION`](https://www.codecademy.com/resources/docs/sql/commands/union) clause is used to combine results that appear from multiple [`SELECT`](https://www.codecademy.com/resources/docs/sql/commands/select) statements and filter duplicates.
0 commit comments