Difference Between “INNER JOIN” and “OUTER JOIN”
Last Updated :
13 May, 2025
Are you working with SQL and struggling to understand the differences between INNER JOIN and OUTER JOIN? These two types of joins are among the most commonly used tools for combining tables in SQL queries. Whether you're analyzing student data or managing customer records, knowing when to use INNER JOIN and OUTER JOIN can make your queries faster, more efficient, and more insightful.
What is a JOIN in SQL?
Joins in SQL are used to combine rows from multiple tables on a specific condition which is a relation between the columns of two tables. Joins allow you to link data together that’s spread across different tables, making it easier to analyze and retrieve meaningful information. Let us consider the two tables student and location and see what the differences would look like by combing tables using different joins.
Table1: students
student_id | student_name |
---|
12 | Gupta |
16 | Girish |
17 | Gupta |
14 | Kunal |
15 | Krishna |
18 | Satish |
Table 2: location
student_id | student_location |
---|
12 | Delhi |
13 | Madras |
15 | Tamil Nadu |
14 | Mumbai |
16 | Telangana |
20 | Punjab |
Types of JOINS
There are several types of joins in SQL, but today we’re going to focus on two main types: INNER JOIN and OUTER JOIN.
1. Inner Join
The INNER JOIN keyword selects records that have matching values in both tables. If there’s no match, the row is excluded from the result set. It's a great option when you only need data that exists in both tables.
Venn diagram representation of the Inner Join:

Example: Let's say we have two tables, one for students and another for locations. We want to see a list of students and their corresponding locations, but only for students who have a location listed.
Query:
SELECT student.student_name, location.student_location
FROM student
INNER JOIN location
ON student.student_id = location.student_id;
Output
student_name | student_location |
---|
Gupta | Delhi |
Girish | Telangana |
Krishna | Tamil Nadu |
Kunal | Mumbai |
Explanation: This will return only the students who have a matching location in the location table. If a student doesn't have a location listed, they won’t appear in the results.
2. Outer Join
OUTER JOIN, on the other hand, is more flexible. It returns all rows from one table and matches data from the other table where possible. If there’s no match, it will still return the row but fill in the missing data with NULL. There are three main types of OUTER JOIN:
1. LEFT JOIN (Left Outer Join)
In left join, we consider the left table completely and the matched attributes (based on condition) in the right table along with the unmatched attributes of the left table. If there’s no match, it returns NULL values for the right table’s columns.
Venn diagram representation of the Left Join:

Example Scenario: We want to see a list of all students and their locations, including students who do not have a location assigned.
SELECT student.student_name, location.student_location
FROM student
LEFT JOIN location
ON student.student_id = location.student_id;
Output
student_name | student_location |
---|
Gupta | Delhi |
Girish | Telangana |
Krishna | Tamil Nadu |
Kunal | Mumbai |
Satish | NULL |
Explanation: This will return only the students who have a matching location in the location table. If a student doesn't have a location listed, they won’t appear in the results.
2. RIGHT JOIN (Right Outer Join)
The RIGHT JOIN is the opposite of LEFT JOIN. It returns all records from the right table and the matched records from the left table. If there is no match, NULL values are returned for the left table’s columns.
Venn diagram representation of the Right Join

Query:
SELECT student.student_name, location.student_location
FROM student
RIGHT JOIN location
ON student.student_id = location.student_id;
Output
student_name | student_location |
---|
Gupta | Delhi |
Girish | Telangana |
Krishna | Tamil Nadu |
Kunal | Mumbai |
NULL | Punjab |
3. FULL JOIN (Full Outer Join)
It is the union of both left join and right join where all the columns of the left table and the right table are considered where the unmatched or unfound attributes of the left table or right table will be placed with NULL in the resultant table.
Venn diagram representation of the full Join:
Query:
SELECT student.student_name, location.student_location
FROM student
FULL JOIN location
ON student.student_id = location.student_id;
Output
student_name | student_location |
---|
Gupta | Delhi |
Girish | Telangana |
Krishna | Tamil Nadu |
Kunal | Mumbai |
Satish | NULL |
NULL | Punjab |
Key Differences Between INNER JOIN and OUTER JOIN
Here is a quick comparison to help us understand when to use INNER JOIN vs. OUTER JOIN:
Join Type | Description | Result |
---|
INNER JOIN | Combines rows from both tables where there’s a match | Only matching rows from both tables |
LEFT JOIN | Combines all rows from the left table with matches from the right table | All rows from the left table and matching rows from the right table |
RIGHT JOIN | Combines all rows from the right table with matches from the left table | All rows from the right table and matching rows from the left table |
FULL JOIN | Combines all rows from both tables | All rows from both tables, with NULLs for non-matching rows |
Conclusion
Joins are fundamental to SQL, providing the capability to merge data from different tables in various ways. INNER JOIN is used to retrieve only the matched records between two tables, whereas OUTER JOIN retrieves matched records along with unmatched records from one or both tables, filling in NULL values where necessary. Now that we understand the differences between INNER JOIN and OUTER JOIN, it's time to practice!
Similar Reads
Difference between Inner Join and Outer Join in SQL
JOINS in SQL are fundamental operations used to combine data from multiple tables based on related columns. They are essential for querying data that is distributed across different tables, allowing you to retrieve and present it as a single or similar result set.In this article, We will learn about
5 min read
Difference between Natural join and Inner Join in SQL
The join operation merges the two tables based on the same attribute name and their datatypes are known as Natural join Unlike INNER JOIN, which requires you to specify the columns and conditions for the join explicitly. In this article, we will also see the differences between them. Let's start wit
3 min read
Difference Between Left Join and Left Outer Join
In SQL language, different joins are used to assemble rows from two or more tables from the related column. The terms "Left Join" and "Left Outer Join" are used interchangeably in SQL but they refer to the same concept. A Left Join retrieves all records from the left table (the first table in the qu
5 min read
Difference Between Right Join and Right Outer Join
Joins in a Database (SQL) are mostly used for combining data or the rows of two or more table records that are based on the same or common attribute. There are various types of Joins like Right Join, Left Join, Full Join, etc. Each join has its own syntax and data-returning capability. In this artic
5 min read
Difference Between Nested Loop Join and Hash Join
These join operations are important to the optimization of SQL operations, especially in guaranteed cases concerning database management systems. Mostly where clause conditions can be transformed into Nested Loop Join and Hash Join main two methods of joining two or more data tables on the same attr
6 min read
Difference Between Left Join and Right Join
In DBMS(Database Management System) Join is an operation that combines the row of two or more tables based on related columns between them. The main purpose of Join is to retrieve the data from multiple tables in other words Join is used to perform multi-table queries. So for that purpose, joins com
5 min read
Difference Between Anti-Join and Semi-Join
In the context of SQL, Anti-join, and semi-join are two essential operations in relational databases used for querying and manipulating data. These operations focus on comparing data from two related tables, but they serve distinct purposes. In this article let us discuss these two operations in det
4 min read
Difference between JOIN and UNION in SQL
Pre-requisites: JOIN, UNION JOIN in SQL is used to combine data from many tables based on a matched condition between them. The data combined using the JOIN statement results in new columns. Consider the two tables: Boys Girls Example: sql> SELECT Boys.Name, Boys.Age, Girls.Address, FROM Boys INN
2 min read
Difference between innerText and innerHTML
innerText and innerHTML are both properties of JavaScript. However, there are differences in which the text is handled. Let us check the syntax of the two and then take an example to look at the differences. Syntax: Let us assume that we have a JavaScript variable called x.let x = document.getElemen
1 min read
Difference between Natural join and Cross join in SQL
AÂ 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 tw
2 min read