In SQL, a Cartesian Join is also called a Cross Join, it performs the cartesian product of records of two or more joined tables. A Cartesian product matches each row of one table to every other row of another table, only when the WHERE condition is not specified in the query. In case the WHERE condition is specified then the Cartesian Join works as an Inner Join.
Syntax of Cartesian Join
With the WHERE clause
SELECT *
FROM table 1
CROSS JOIN table 2
WHERE condition
Without the WHERE Clause
SELECT table1.column1 , table2.column2...
FROM table1, table2...
CROSS JOIN table2;
How to Perform Cartesian Join on Tables?
To Perform follow the given steps :
Step 1: To start with first we need to create a Database. For creating a new database use the below command. As an example, we are creating a new database GeeksForGeeks.
Query:
CREATE DATABASE GeeksForGeeks
Output:

Step 2: To start working with our database we need to use the database. For this we use the below command.
Query:
USE GeeksForGeeks;
Output:

Step 3: Now we need to create tables in this database so as an example we are creating two tables. One is Students and other one is Library. Use the below commands to create the tables.
Query:
CREATE TABLE STUDENTS(
ID INT,
NAME VARCHAR(20),
BRANCH VARCHAR(20),
NUMBER INT);
CREATE TABLE LIBRARY(
BOOK_ID INT,
BOOK_NAME VARCHAR(20),
ISSUED_ON DATE,
DUE_DATE DATE);

To view the structure of both tables we use the DESC command.
Query :
DESC STUDENTS;
DESC LIBRARY;
Step 3_1
Step 4: Now to perform Cartesian Join first we will insert some data in the rows of both STUDENTS and LIBRARY table.
Query:
INSERT INTO STUDENTS VALUES(1,'SURYANSH JOHARI','CS',984012);
INSERT INTO STUDENTS VALUES(2,'AMAN SHARMA','IT',771346);
INSERT INTO STUDENTS VALUES(3,'DEV VERMA','ME',638587);
INSERT INTO STUDENTS VALUES(4,'JOY SMITH','CE',876691);
INSERT INTO STUDENTS VALUES(5,'CHARLES GATTO','EE',997679);
INSERT INTO LIBRARY VALUES(121,'RD SHARMA','2023-01-01','2023-01-08');
INSERT INTO LIBRARY VALUES(236,'GATE CRACKER','2023-02-02','2023-02-09');
INSERT INTO LIBRARY VALUES(352,'MORRIS MANO','2023-03-03','2023-03-10');
INSERT INTO LIBRARY VALUES(970,'NK PUBLICATIONS','2023-04-04','2023-04-11');
INSERT INTO LIBRARY VALUES(648,'BIG BANG THEORY','2023-05-05','2023-05-12');
Output:
Step 4
Step 5: After data has been stored in both the tables now we can perform the Cartesian Join on both the tables. As an example here we are doing Cartesian Join with the WHERE clause and finding the records only where NAME of student is Suryansh Johari .
Query:
SELECT *
FROM STUDENTS
CROSS JOIN LIBRARY
WHERE NAME ="SURYANSH JOHARI";
Output:
Step 5
Conclusion
In this article, we have learned how to perform Cartesian Join or Cross Join on tables of a SQL database. Cartesian Join is important when there is a need to obtain all the combinations of rows present in the tables of a database. Cartesian Join with WHERE clause behaves as a Inner join and without WHERE clause it simply performs cartesian product of all rows of all the tables as mentioned in the SQL query.
Similar Reads
Anti Join in R
The anti-join operation in R Programming Language provided by the anti_join() function in the dplyr package, allows us to perform this comparison efficiently. This article will explore the anti-join operation in detail, providing explanations and examples to illustrate its usage. Anti Join in R What
4 min read
SQL | Join (Cartesian Join & Self Join)
In SQL, CARTESIAN JOIN (also known as CROSS JOIN) and SELF JOIN are two distinct types of joins that help combine rows from one or more tables based on certain conditions. While both joins may seem similar, they serve different purposes. Letâs explore both in detail.CARTESIAN JOINA Cartesian Join or
4 min read
Conditional Join
DBMS or Database Management Systems consist of data collected from various sources. Database administrators and analysts use this data to analyze the collected data. Database administrators execute the query through which some output is generated, the conditions are passed through the query. This qu
5 min read
Joins in DBMS
A join is an operation that combines the rows of two or more tables based on related columns. This operation is used for retrieving the data from multiple tables simultaneously using common columns of tables. In this article, we are going to discuss every point about joins.What is Join?Join is an op
6 min read
SQL CROSS JOIN
In SQL, the CROSS JOIN is a unique join operation that returns the Cartesian product of two or more tables. This means it matches each row from the left table with every row from the right table, resulting in a combination of all possible pairs of records. In this article, we will learn the CROSS JO
3 min read
Cartesian Product of Sets
'Product' mathematically signifies the result obtained when two or more values are multiplied together. For example, 45 is the product of 9 and 5. One must be familiar with the basic operations on sets like Union and Intersection, which are performed on 2 or more sets. Cartesian Product is also one
7 min read
MySQL CROSS JOIN
MySQL is an open-source relational database management system that uses Structured Query Language (SQL) to manipulate databases. It stores data in a table format. It provides various statements to perform Create, Read, Update, and Delete operations on a database table. Among these operations, MySQL
5 min read
PL/SQL Cross Join
Combining data from several tables is an ordinary procedure in the field of relational databases. The Cross Join is one of the several table joining techniques offered by PL/SQL, Oracle's procedural SQL extension. To improve your comprehension, this article will provide you with an introduction to C
7 min read
Join Dependencies in DBMS
Join Dependency (JD) can be illustrated as when the relation R is equal to the join of the sub-relations R1, R2,..., and Rn are present in the database. Join Dependency arises when the attributes in one relation are dependent on attributes in another relation, which means certain rows will exist in
5 min read
Merge Join in DBMS
Merge be part of is a hard and fast-based be part of operation used in database control systems (DBMS) to mix rows from or extra tables based on an associated column among them. It is mainly efficient whilst the tables involved are large and while they are each sorted on the be a part of the key, wh
7 min read