SQLize Online / PHPize Online

A A A
Share      Blog   Popular

CROSS JOIN

Tags: MySQL 5.7 MySQL 8.0 MariaDB 10 SQLite 3 PostgreSQL 11 PostgreSQL 12 PostgreSQL 13 PostgreSQL 14 PostgreSQL 15 MS SQL Server 2017 MS SQL Server 2019 MS SQL Server 2022 Oracle Database 19c Oracle Database 19c (HR) Oracle Database 21c

The CROSS JOIN is used to generate a paired combination of each row of the first table with each row of the second table. This join type is also known as cartesian join.

If WHERE clause is used with CROSS JOIN, it functions like an INNER JOIN.

The below code returns all combination Meals with all Drinks

CREATE TABLE Meals(MealName VARCHAR(100)); CREATE TABLE Drinks(DrinkName VARCHAR(100)); INSERT INTO Drinks VALUES('Orange Juice'), ('Tea'), ('Cofee'); INSERT INTO Meals VALUES('Omlet'), ('Fried Egg'), ('Sausage'); SELECT * FROM Meals CROSS JOIN Drinks;