SQLize Online / PHPize Online  /  SQLtest Online

Share      Blog   Popular


Tags: MySQL 5.7 MySQL 5.7 Sakila (ReadOnly) MySQL 8.0 MySQL 8.0 Sakila (ReadOnly) MariaDB 10 MariaDB 10 Sakila (ReadOnly) SQLite 3 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 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;