Open In App

Difference between Natural join and Cross join in SQL

Last Updated : 12 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

JOIN clause is used to combine rows from two or more tables, based on a related data column in between them. Natural Join and Cross Join both serve different purposes in database management. While the former matches column with same name, the latter outputs all possible row combinations between two tables.

Natural Join

Natural Join joins two tables based on same attribute name and data types. The resulting table will contain all the attributes of both the tables but only one copy of each common column. It is denoted by a symbol (⨝). It is the combination of projection and filtered cartesian product.

Natural Join is beneficial when you need to:

  • Simplify Queries: It eliminates the condition to match the records.
  • Reduce Errors: It automatically matches columns with the same name, reducing error.
  • Improve Readability: It simplifies SQL code, making it more readable and understandable.

Example

Consider the two tables given below:

Table A (Employees)

emp_idnamedepartment_id
1Alice101
2Bob102
3Charlie103

Table B(Departments)

department_iddepartment_name
101HR
102Engineering
103Marketing

Consider the given query

SELECT *
FROM Employees E NATURAL JOIN Departments D;

Output :

Result of the Natural Join on both table

emp_idnamedepartment_iddepartment_name
1Alice101HR
2Bob102Engineering
3Charlie103Marketing

Cross Join

Cross Join will produce cross or Cartesian product of two tables if there is no condition specifies. The resulting table will contain all the attributes of both the tables including duplicate or common columns also.

MySQL CROSS JOIN

Example

Consider the two tables and the query is given below:

Student Table:

Marks Table:

SELECT *
FROM Student S CROSS JOIN Marks M;

Output:

Difference between Natural Join and Cross Join in SQL

Natural JoinCross Join
Natural Join joins two tables based on same attribute name and datatypes.Cross Join will produce cross or cartesian product of two tables .
The resulting table will contain all the attributes of both the tables but keep only one copy of each common column.The resulting table will contain all the attribute of both the tables including duplicate columns also.
If there is no condition specifies then it returns the rows based on the common columnIf there is no condition specifies then it returns all possible pairing of rows from both the tables whether they are matched or unmatched
Syntax:
SELECT * FROM table1 NATURAL JOIN table2
Syntax:
SELECT * FROM table1 CROSS JOIN table2

Next Article

Similar Reads