Menu

SQL Inner Join – The Ins and Outs of SQL Inner Join

An Inner Join in SQL is a method to combine rows from two or more tables based on a related column

Written by Jagdeesh | 2 min read

An Inner Join in SQL is a method to combine rows from two or more tables based on a related column

SQL, or Structured Query Language, provides us with several ways to combine data from different tables. One of the essential methods to achieve this is by using an Inner Join.

SQL Inner Join Syntax

An Inner Join in SQL is a method to combine rows from two or more tables based on a related column. Let’s start by exploring its syntax

sql
SELECT table1.column1, table2.column2...
FROM table1
INNER JOIN table2
ON table1.matching_column = table2.matching_column;

This command creates a new table that includes rows where the join condition is true.

Unpacking the Syntax with Examples

To make this clearer, let’s take a look at an example. I will use two simple tables, Orders and Customers.

Here’s the Orders table:

output
| OrderID | CustomerID | Product    |
|---------|------------|------------|
| 1       | 101        | Apples     |
| 2       | 102        | Bananas    |
| 3       | 103        | Cherries   |
| 4       | 104        | Dates      |
| 5       | 105        | Eucalyptus |

And the Customers table:

output
| CustomerID | Name     | Country  |
|------------|----------|----------|
| 101        | Alice    | USA      |
| 102        | Bob      | UK       |
| 103        | Charlie  | Canada   |
| 104        | David    | Australia|

Our goal is to create a new table that combines the Name from the Customers table with OrderID and Product from the Orders table, for each matching CustomerID.

To achieve this, I’ll use the Inner Join syntax as follows:

sql
SELECT Orders.OrderID, Customers.Name, Orders.Product
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID = Customers.CustomerID;

Executing this command gives us a new table:

output
| OrderID | Name     | Product   |
|---------|----------|-----------|
| 1       | Alice    | Apples    |
| 2       | Bob      | Bananas   |
| 3       | Charlie  | Cherries  |
| 4       | David    | Dates     |

This result set only includes the customers who have an order and their respective orders, according to the matching CustomerID.

Wrapping Up

Understanding and using Inner Join operation is key to efficient SQL data handling. It enables you to gather and correlate data from disparate tables based on common attributes.

Free Course
Master Core Python — Your First Step into AI/ML

Build a strong Python foundation with hands-on exercises designed for aspiring Data Scientists and AI/ML Engineers.

Start Free Course
Trusted by 50,000+ learners
Jagdeesh
Written by
Related Course
Master SQL — Hands-On
Join 5,000+ students at edu.machinelearningplus.com
Explore Course
Free Callback - Limited Slots
Not Sure Which Course to Start With?
Talk to our AI Counsellors and Practitioners. We'll help you clear all your questions for your background and goals, bridging the gap between your current skills and a career in AI.
10-digit mobile number
📞
Thank You!
We'll Call You Soon!
Our learning advisor will reach out within 24 hours.
(Check your inbox too — we've sent a confirmation)
⚡ Before you go

Python.
SQL. NumPy.
All free.

Get the exact 10-course programming foundation that Data Science professionals use.

🐍
Core Python — from first line to expert level
📈
NumPy & Pandas — the #1 libraries every DS job needs
🗃️
SQL Levels I–III — basics to Window Functions
📄
Real industry data — Jupyter notebooks included
R A M S K
57,000+ students
★★★★★ Rated 4.9/5
⚡ Before you go
Python. SQL.
All Free.
R A M S K
57,000+ students  ★★★★★ 4.9/5
Get Free Access Now
10 courses. Real projects. Zero cost. No credit card.
New learners enrolling right now
🔒 100% free ☕ No spam, ever ✓ Instant access
🚀
You're in!
Check your inbox for your access link.
(Check Promotions or Spam if you don't see it)
Or start your first course right now:
Start Free Course →
Scroll to Top
Scroll to Top
Course Preview

Machine Learning A-Z™: Hands-On Python & R In Data Science

Free Sample Videos:

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science