-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1105 from yangj1211/cross-join
add doc of Cross join
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
docs/MatrixOne/Reference/SQL-Reference/Data-Query-Language/join/cross-join.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# **CROSS JOIN** | ||
|
||
## **语法说明** | ||
|
||
`CROSS JOIN` 用于实现两个表的笛卡尔积,也就是生成两个表中所有行的组合。 | ||
|
||
## **语法结构** | ||
|
||
``` | ||
>SELECT column_list | ||
FROM table1 | ||
CROSS JOIN table2; | ||
``` | ||
|
||
## **示例** | ||
|
||
```sql | ||
CREATE TABLE Colors ( | ||
color_id INT AUTO_INCREMENT, | ||
color_name VARCHAR(50), | ||
PRIMARY KEY (color_id) | ||
); | ||
|
||
CREATE TABLE Fruits ( | ||
fruit_id INT AUTO_INCREMENT, | ||
fruit_name VARCHAR(50), | ||
PRIMARY KEY (fruit_id) | ||
); | ||
|
||
INSERT INTO Colors (color_name) VALUES ('Red'), ('Green'), ('Blue'); | ||
INSERT INTO Fruits (fruit_name) VALUES ('Apple'), ('Banana'), ('Cherry'); | ||
|
||
mysql> SELECT c.color_name, f.fruit_name FROM Colors c CROSS JOIN Fruits f;--生成一个包含所有颜色和所有水果组合的结果集 | ||
+------------+------------+ | ||
| color_name | fruit_name | | ||
+------------+------------+ | ||
| Red | Apple | | ||
| Green | Apple | | ||
| Blue | Apple | | ||
| Red | Banana | | ||
| Green | Banana | | ||
| Blue | Banana | | ||
| Red | Cherry | | ||
| Green | Cherry | | ||
| Blue | Cherry | | ||
+------------+------------+ | ||
9 rows in set (0.00 sec) | ||
|
||
mysql> SELECT c.color_name,f.fruit_name FROM Colors c CROSS JOIN Fruits f WHERE c.color_name = 'Red' AND f.fruit_name = 'Apple';--筛选出特定颜色和特定水果的组合 | ||
+------------+------------+ | ||
| color_name | fruit_name | | ||
+------------+------------+ | ||
| Red | Apple | | ||
+------------+------------+ | ||
1 row in set (0.01 sec) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters