From 195c44076606cc2c72834a6ff616ba41d0ad96b9 Mon Sep 17 00:00:00 2001 From: yangj1211 Date: Wed, 10 Jul 2024 15:28:53 +0800 Subject: [PATCH 1/2] add doc of cross join --- .../Data-Query-Language/join/cross-join.md | 56 +++++++++++++++++++ .../Data-Query-Language/join/join.md | 2 +- mkdocs.yml | 1 + 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 docs/MatrixOne/Reference/SQL-Reference/Data-Query-Language/join/cross-join.md diff --git a/docs/MatrixOne/Reference/SQL-Reference/Data-Query-Language/join/cross-join.md b/docs/MatrixOne/Reference/SQL-Reference/Data-Query-Language/join/cross-join.md new file mode 100644 index 0000000000..170c857acb --- /dev/null +++ b/docs/MatrixOne/Reference/SQL-Reference/Data-Query-Language/join/cross-join.md @@ -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) +``` diff --git a/docs/MatrixOne/Reference/SQL-Reference/Data-Query-Language/join/join.md b/docs/MatrixOne/Reference/SQL-Reference/Data-Query-Language/join/join.md index cf0109609b..39247157d9 100644 --- a/docs/MatrixOne/Reference/SQL-Reference/Data-Query-Language/join/join.md +++ b/docs/MatrixOne/Reference/SQL-Reference/Data-Query-Language/join/join.md @@ -4,7 +4,7 @@ ``JOIN`` 用于把来自两个或多个表的行结合起来。 -下图展示了 ``LEFT JOIN``、``RIGHT JOIN``、``INNER JOIN``、和 ``OUTER JOIN``。 +下图展示了 ``LEFT JOIN``、``RIGHT JOIN``、``INNER JOIN``、和 ``JOIN``。 **``LEFT JOIN``** diff --git a/mkdocs.yml b/mkdocs.yml index bc4467006b..d95226b67b 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -353,6 +353,7 @@ nav: - SUBQUERY with IN: MatrixOne/Reference/SQL-Reference/Data-Query-Language/subqueries/subquery-with-in.md - JOIN: - JOIN 概述: MatrixOne/Reference/SQL-Reference/Data-Query-Language/join/join.md + - CROSS JOIN: MatrixOne/Reference/SQL-Reference/Data-Query-Language/join/cross-join.md - INNER JOIN: MatrixOne/Reference/SQL-Reference/Data-Query-Language/join/inner-join.md - LEFT JOIN: MatrixOne/Reference/SQL-Reference/Data-Query-Language/join/left-join.md - RIGHT JOIN: MatrixOne/Reference/SQL-Reference/Data-Query-Language/join/right-join.md From 8f4fefa56f9aaf738b4dd2e2fd752591f549b920 Mon Sep 17 00:00:00 2001 From: yangj1211 Date: Wed, 10 Jul 2024 15:57:04 +0800 Subject: [PATCH 2/2] add doc of cross join --- .../Reference/SQL-Reference/Data-Query-Language/join/join.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/MatrixOne/Reference/SQL-Reference/Data-Query-Language/join/join.md b/docs/MatrixOne/Reference/SQL-Reference/Data-Query-Language/join/join.md index 39247157d9..cf0109609b 100644 --- a/docs/MatrixOne/Reference/SQL-Reference/Data-Query-Language/join/join.md +++ b/docs/MatrixOne/Reference/SQL-Reference/Data-Query-Language/join/join.md @@ -4,7 +4,7 @@ ``JOIN`` 用于把来自两个或多个表的行结合起来。 -下图展示了 ``LEFT JOIN``、``RIGHT JOIN``、``INNER JOIN``、和 ``JOIN``。 +下图展示了 ``LEFT JOIN``、``RIGHT JOIN``、``INNER JOIN``、和 ``OUTER JOIN``。 **``LEFT JOIN``**