Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
Difference Between Left Join and Right Join
Next article icon

Difference Between Left Join and Left Outer Join

Last Updated : 18 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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 query) and matches them with records from the right table (the second table) based on a specified condition.

In this article, we will explore the concepts with examples of Left Join and Left Outer Join. along with their examples and differences between them.

Left Join

Left Join in SQL language is used to return all the data or records from the left table and the matching data or records from the right table. In the scenario, where there is no match, then the join still consists of the rows from the left table and displays the NULL values for the columns of the right table.

In the context of the query, below is the syntax of the Left Join.

Syntax:

SELECT columns FROM left_table

LEFT JOIN right_table ON

join_condition;

Now, let's understand the Left Join through a simple example:

Example:

1. Customer_Data Table:

customer_id

customer_name

1

Gaurav

2

Anjali

3

Ramesh

2. Orders_Data Table:

order_id

customer_id

order_date

1

1

2023-01-23

2

1

2023-02-03

3

3

2023-03-05

4

4

2023-04-10

Query for Left Join

Suppose We need to retrieve a list of all customers along with their corresponding order details, including customers who have not placed any orders.

SELECT Customer_Data.customer_id, Customer_Data.customer_name,
Orders_Data.order_id, Orders_Data.order_date
FROM Customers_Data
LEFT JOIN Orders ON
Customers_Data.customer_id = Orders_Data.customer_id;

Output:

customer_id

customer_name

order_id

order_date

1

Gaurav

1

2023-01-23

1

Gaurav

2

2023-02-03

2

Anjali

NULL

NULL

3

Ramesh

3

2023-03-05

Explanation: In the above example. Left Join includes all rows from the left table (Customer_Data) and matched them with the corresponding rows of the right table (Orders_Data). Here, Customer Gaurav has 2 orders, Anjali has no orders (NULL), and Ramesh has 1 order.

Left Outer Join

The concept of Left Outer Join is similar and same to the Left Join and both these terms are interchangeably used. The keyword used here is "Outer" which is optional and also doesn't impact the result.

Syntax:

SELECT columns

FROM left_table

LEFT OUTER JOIN right_table ON

join_condition;

Example:

Let's consider the same tables used in the above Left Join Example:

Query for Left Outer Join

Let's retrieve a list of all customers along with their order details, if any. Even if a customer has not placed an order, their information should still appear in the result.

SELECT Customer_Data.customer_id, Customer_Data.customer_name,
Orders_Data.order_id, Orders_Data.order_date FROM Customers_Data
LEFT OUTER JOIN Orders ON
Customers_Data.customer_id = Orders_Data.customer_id;

Output

customer_id

customer_name

order_id

order_date

1

Gaurav

1

2023-01-23

1

Gaurav

2

2023-02-03

2

Anjali

NULL

NULL

3

Ramesh

3

2023-03-05

4

NULL

NULL

NULL

Explanation: In the above example, non-matching records from the right table ("Orders_Data") are included, and NULL values are shown for the right table columns. Thus, the customer with 'customer_id' 4 in the Orders_Data table, which doesn't have a matching record in the Customer_Data table is also included in the result set and the NULL values are shown, which was not displayed in the Left Join condition.

Difference Between Left Join and Left Outer Join

Parameter

Left Join

Outer Join

Matching Records

In Left Join, matching records from the right table are included.

In Left Outer Join, matching records from the right tables are included.

Non-Matching Records

In Left Join, non-matching records from the rightmost table are excluded.

In Left Outer Join, non-matching records from the right table are included and the NULL value is displayed for the right table columns.

Join Keyword

LEFT JOIN

LEFT OUTER JOIN

Null Values

No NULL values are shown for the right table columns.

NULL values are shown for the right table columns in case there is no match.

Syntax

SELECT columns FROM left_table LEFT JOIN right_table ON join_condition;

SELECT columns FROM left_table LEFT OUTER JOIN right_table ON join_condition;

Conclusion

In conclusion, the Left Join retrieves all records from the left table and matches them with corresponding records from the right table, filling in NULL values where there are no matches. While "Left Outer Join" is the technically accurate term, "Left Join" is a more common shorthand. Understanding that these terms are synonymous helps prevent confusion and ensures effective use of joins when combining data from multiple tables in SQL queries.


Next Article
Difference Between Left Join and Right Join

G

gpancomputer
Improve
Article Tags :
  • DBMS
  • Difference Between
  • SQL
  • Databases
  • SQL Difference Between

Similar Reads

  • 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 “INNER JOIN” and “OUTER JOIN”
    Joins in SQL are essential tools that allow us to combine rows from multiple tables based on specific conditions, often involving a relation between columns in those tables. These joins help in pulling related data together in a meaningful way. Among the most commonly used joins are INNER JOIN and O
    5 min read
  • Difference between Nested Loop join and Sort Merge Join
    1. Nested Loop Join : Nested Loop Join is the simplest join algorithm which usually has better performance than all other types of joins due to a lesser number of comparisons involved in it. Each row in the outer table is compared to each row in the inner table. The Nested Loop Join algorithm for 2
    3 min read
  • Difference between Hash Join and Sort Merge Join
    1. Hash Join : It is also known as "go-to-guy" in case of join operators. This means that in case no other join is preferred (maybe due to no sorting or indexing etc), then, Hash join is used. Hash join is best algorithm when large, unsorted, and non-indexed data (residing in tables) is to be joined
    3 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 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 abou
    5 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 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
    5 min read
  • Python Pandas - Difference between INNER JOIN and LEFT SEMI JOIN
    In this article, we see the difference between INNER JOIN and LEFT SEMI JOIN. Inner Join An inner join requires two data set columns to be the same to fetch the common row data values or data from the data table. In simple words, and returns a data frame or values with only those rows in the data fr
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences