Cartesian JOIN

Function

Cartesian JOIN joins each record of table A with all records in table B. For example, if there are m records in table A and n records in table B, m x n records will be generated by Cartesian JOIN.

Syntax

SELECT attr_expr_list FROM table_reference
  CROSS JOIN table_reference ON join_condition;

Keyword

The join_condition is the condition for joining. If join_condition is always true, for example 1=1, the join is Cartesian JOIN. Therefore, the number of records output by Cartesian join is equal to the product of the number of records in the joined table. If Cartesian join is required, use the special keyword CROSS JOIN. CROSS JOIN is the standard way to calculate Cartesian product.

Precautions

The to-be-joined table must exist. Otherwise, an error is reported.

Example

To return all the JOIN results of the student name and course name from the student_info and course_info tables, run the following statement:

SELECT student_info.name, course_info.courseName FROM student_info
  CROSS JOIN course_info ON (1 = 1);