Sitemap

SQL Joins Explained with Real Examples | SQL Interview Series #1

4 min readJun 24, 2026

--

Press enter or click to view image in full size

If you’re preparing for SQL interviews, there’s one topic you simply cannot afford to skip: Joins.

During my recent interview preparation, I noticed that almost every company asked at least one question related to joins. Sometimes it was a direct question like “What’s the difference between INNER JOIN and LEFT JOIN?” and other times it was hidden inside a business scenario.

In this article, we’ll understand SQL joins using simple examples that are commonly asked in interviews and used in real-world applications.

Why Do We Need Joins?

In real-world databases, data is usually spread across multiple tables rather than stored in a single table.

Let’s take an example of an e-commerce application.

Customers Table

Table: Customers

Orders Table

Table: Orders

Now suppose we want to see the customer names along with their order amounts. Since the information exists in different tables, we need a JOIN.

INNER JOIN

An INNER JOIN returns only the records that have matching values in both tables.

Query

SELECT
c.CustomerName,
o.Amount
FROM Customers c
INNER JOIN Orders o
ON c.CustomerID = o.CustomerID;

Result

Output

Only matching records are returned.

Think of INNER JOIN as the intersection between two tables.

LEFT JOIN

A LEFT JOIN returns all records from the left table and matching records from the right table.

Let’s add another customer who hasn’t placed an order yet.

New Record

Query

SELECT
c.CustomerName,
o.Amount
FROM Customers c
LEFT JOIN Orders o
ON c.CustomerID = o.CustomerID;

Result

Output

Notice that customers without orders are still displayed. Their order amount appears as NULL.

RIGHT JOIN

A RIGHT JOIN works exactly opposite to a LEFT JOIN. It returns all records from the right table and matching records from the left table.

Although MySQL supports RIGHT JOIN, many developers prefer using LEFT JOIN because it is generally easier to read and maintain.

FULL OUTER JOIN

A FULL OUTER JOIN returns:

  • All matching records
  • All records from the left table
  • All records from the right table

MySQL does not directly support FULL OUTER JOIN, but it can be achieved using UNION.

SELF JOIN

A SELF JOIN occurs when a table is joined with itself.

Get Varsha Vishwakarma’s stories in your inbox

Join Medium for free to get updates from this writer.

One common example is an Employee table where each employee has a manager.

SELECT
e.EmployeeName,
m.EmployeeName AS ManagerName
FROM Employees e
LEFT JOIN Employees m
ON e.ManagerID = m.EmployeeID;

This is a very common SQL interview question.

Frequently Asked Interview Questions

1. What is the difference between INNER JOIN and LEFT JOIN?

  • INNER JOIN returns only matching records.
  • LEFT JOIN returns all records from the left table and matching records from the right table.

2. Which JOIN is used most often in real projects?

INNER JOIN and LEFT JOIN are by far the most commonly used joins in production systems.

3. Can we join more than two tables?

Absolutely.

A single query can join multiple tables depending on business requirements.

4. How do joins affect performance?

Joins on large datasets can be expensive. Creating indexes on the columns used in joins can significantly improve query performance.

Real-World Example

Imagine you’re building a food delivery application.

You may have separate tables for:

  • Users
  • Orders
  • Restaurants
  • Payments

To generate a report showing customer name, restaurant name, order amount, and payment status, you’ll need multiple joins.

This is exactly why joins are one of the most important concepts for backend developers, data analysts, and database engineers.

Final Thoughts

Learning joins is not about memorizing definitions. It’s about understanding how data is related across tables and how those relationships help answer business questions.

If you’re preparing for SQL interviews, focus on mastering:

  • INNER JOIN
  • LEFT JOIN
  • SELF JOIN
  • Real-world business scenarios

These concepts appear repeatedly in interviews and are used extensively in real applications.

In the next article of this SQL Interview Series, we’ll explore SQL Subqueries with practical examples and interview questions.

Happy Learning! 🚀

--

--

Varsha Vishwakarma
Varsha Vishwakarma

Written by Varsha Vishwakarma

Data Engineer | Exploring data, solving problems, and sharing practical lessons on SQL, Power BI, and analytics.