Help Center/ AI DataLake/ Spark reference/ Query Syntax/ JOINS/ CROSS JOIN (Cartesian Join)
Updated on 2026-11-06 GMT+08:00

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);