Different Types of Joins in SQL

Abhilash Jose
Abhilash Jose  - Data Science Specialist
3 Min Read

When working with databases, understanding how to connect different tables is crucial for effective data analysis. SQL joins are powerful tools that let you combine data from two or more tables based on related columns. By mastering joins, you can extract meaningful insights from your datasets, making your analysis much more comprehensive. Let’s explore the four main types of joins you’ll encounter in SQL: INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN.

1. INNER JOIN

An INNER JOIN returns only the rows that have matching values in both tables. If there’s no match, those rows won’t appear in the result set.

Syntax:

Example:

2. LEFT JOIN (or LEFT OUTER JOIN)

A LEFT JOIN returns all the rows from the left table and the matched rows from the right table. If there’s no match, NULL values will fill in the gaps on the right side.

Syntax:

Example:

3. RIGHT JOIN (or RIGHT OUTER JOIN)

A RIGHT JOIN returns all the rows from the right table and the matched rows from the left table. If there’s no match, NULLs will fill in the gaps on the left side.

Syntax:

Example:

4. FULL OUTER JOIN

A FULL OUTER JOIN combines the results of both LEFT JOIN and RIGHT JOIN. It returns all rows from both tables, with NULLs in places where there are no matches.

Syntax:

Example:

Summary of Joins

Join TypeDescription
INNER JOINReturns only matching rows from both tables.
LEFT JOINReturns all rows from the left table and matched rows from the right table.
RIGHT JOINReturns all rows from the right table and matched rows from the left table.
FULL OUTER JOINReturns all rows from both tables, with NULLs where there are no matches.

By understanding these joins, you can efficiently retrieve and analyze data across multiple tables, unlocking deeper insights into your datasets!

Share this Article
By Abhilash Jose Data Science Specialist
Follow:
Abhilash Jose is a data science specialist from India. He specializes in data analysis and is well-known for his expertise in areas such as machine learning and statistical modeling. His skills encompass a wide range of techniques, including data mining, predictive modeling, and data visualization.
Leave a comment