Skip to content

Commit 1e9e9cb

Browse files
[Enhancement] Added the outer join (#8058)
* 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
1 parent 1219a47 commit 1e9e9cb

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

content/sql/concepts/joins/joins.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,40 @@ An `OUTER JOIN` will combine rows from different tables even if the join conditi
4040
- [`RIGHT JOIN`](https://www.codecademy.com/resources/docs/sql/commands/right-join), which combines matches with all rows from the right-side table.
4141
- [`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.
4242

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+
SELECT shirts.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+
4377
## UNION
4478

4579
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

Comments
 (0)