SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular

CROSS JOIN

Tags: MariaDB 11.4 MariaDB 11.5 MariaDB 10 MariaDB 10 Sakila (ReadOnly) MySQL 5.7 MySQL 5.7 Sakila (ReadOnly) MySQL 8.0 MySQL 8.0 Sakila (ReadOnly) SQLite 3 SQLite 3 Preloaded PostgreSQL 10 Bookings (ReadOnly) PostgreSQL 11 PostgreSQL 12 PostgreSQL 13 PostgreSQL 14 PostgreSQL 15 MS SQL Server 2017 MS SQL Server 2019 MS SQL Server 2022 MS SQL Server 2022 AdventureWorks (ReadOnly) Firebird 4.0 Firebird 4.0 (Employee) Oracle Database 19c (HR) Oracle Database 21c Oracle Database 23c Free SOQOL

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;

CROSS JOIN - New snippets