CROSS JOIN (Cartesian Join)
Function
A CROSS JOIN combines each record from the first table with all records from the second table. If the first table has m records and the second table has n records, the result will have m * n records.
Syntax
SELECT attr_expr_list FROM table_reference CROSS JOIN table_reference [ON join_condition]; SELECT attr_expr_list FROM table_reference CROSS JOIN table_reference;
Parameters
| Parameter | Description |
|---|---|
| attr_expr_list | The list of query column expressions, specifying the columns to be returned. |
| table_reference | The table name or subquery to be joined. Must be an existing table. Otherwise, an error is reported. |
| CROSS JOIN | The CROSS JOIN keyword, the standard way to compute a Cartesian product. |
| join_condition | An optional join condition. If this condition is always true (e.g., 1 = 1), the join is a Cartesian join. A CROSS JOIN without an ON clause also represents a Cartesian product. |
Precautions
- The tables to be joined must already exist. Otherwise, an error is reported.
- CROSS JOIN is the standard way to compute a Cartesian product. If the ON clause is omitted, the Cartesian product of the two tables is computed directly.
- Cartesian joins can produce a large number of records. Use with caution.
Example
Return all combinations of student names and course names from the student_info and course_info tables.
SELECT student_info.name, course_info.courseName FROM student_info CROSS JOIN course_info;
Equivalent syntax (using an always-true ON condition):
SELECT student_info.name, course_info.courseName FROM student_info CROSS JOIN course_info ON (1 = 1);
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot