Open In App

SQL CROSS JOIN

Last Updated : 21 Nov, 2025
Comments
Improve
Suggest changes
5 Likes
Like
Report

SQL CROSS JOIN creates a Cartesian product of two tables, meaning it returns every possible combination of rows from both tables. It does not use a join condition, and the total number of rows in the result is the number of rows in the first table multiplied by the number of rows in the second table. It is useful for generating all combinations of data.

cross_join
CROSS JOIN

Syntax:

SELECT * FROM table1
CROSS JOIN table2;

Examples of SQL CROSS JOIN

Before diving into queries, let’s create two sample tables: Customer and Orders. These tables will help us understand how CROSS JOIN combines data into multiple combinations.

customer-1
Customers
Orders
Orders

Query:

SELECT * 
FROM Customer
CROSS JOIN Orders;

Output:

Orders-output

Explanation: CROSS JOIN combines every row from the Customer table with every row from Orders table. Since there are 2 customers and 2 orders, result contains 2 × 2 = 4 rows.

Suggested Quiz
5 Questions

What does a CROSS JOIN return?

  • A

    Only matching rows from two tables

  • B

    All rows from the first table only

  • C

    All combinations of rows from both tables

  • D

    Rows filtered by common column values

Explanation:

CROSS JOIN generates a Cartesian product, every row paired with every row.

What condition is required for a CROSS JOIN?

  • A

    A primary key match

  • B

    A join condition using ON

  • C

    A WHERE clause must be used

  • D

    No condition is required

Explanation:

CROSS JOIN does not use an ON condition; it simply pairs all rows.

If table A has 5 rows and table B has 3 rows, how many rows will a CROSS JOIN produce?

  • A

    15

  • B

    8

  • C

    3

  • D

    5

Explanation:

Total rows = 5 * 3 = 15 combinations.

What is a common use case for CROSS JOIN?

  • A

    Removing duplicate values

  • B

    Generating all possible combinations

  • C

    Finding unmatched records

  • D

    Filtering based on conditions

Explanation:

CROSS JOIN is ideal when you need every combination of two datasets.

What happens if both tables used in a CROSS JOIN are empty?

  • A

    The query errors out

  • B

    The result shows NULL for all columns

  • C

    The result contains zero rows

  • D

    The result contains one row

Explanation:

No rows × no rows = no combinations, so result is empty.

Quiz Completed Successfully
Your Score :   2/5
Accuracy :  0%
Login to View Explanation
1/5 1/5 < Previous Next >

Explore