MySQL CROSS JOIN

MySQL CROSS JOIN is also referred to as Cartesian Product. For every row in the LEFT Table of the CROSS JOIN all the rows from the RIGHT table are returned and Vice-Versa (i.e.result will have the Cartesian product of the rows from join tables).

To demonstrate MySQL CROSS JOIN with extensive list of examples and visual representation let us create Customers and Orders tables as shown in the following image by executing the following script

No.of Rows in the Result of Cross Join = (No. of Rows in LEFT Table) * (No. of Rows in RIGHT Table)
mysql-joins-demo-tables

EXAMPLE 1: In the below example we are doing a CROSS JOIN between the Customers and Orders Table. So in the result, for each row in the Customer table we will have all the records from the Orders table.

No.of Rows in the Result of Cross Join = (No. of Rows in Customers Table) * (No. of Rows in Orders Table)

RESULT
mysql-cross-join

Leave a Reply

Your email address will not be published. Required fields are marked *