Checking your session…
Module 10: SQL Joins

10.1 What are Joins? (Overview)

Level: 10 | Version: v1.1 | Author: Meptrasoft

Overview

A JOIN is used to combine related data from two or more tables.

For example:

TEXT
Students
   +
Courses
   ↓
JOIN
   ↓
Combined Result

Joins are useful when related information is stored in separate tables.

There are six common join types:

Join Type Main Idea
INNER JOIN Matching rows from both tables
LEFT JOIN All left rows + matching right rows
RIGHT JOIN All right rows + matching left rows
FULL JOIN All rows from both tables
SELF JOIN A table joined with itself
CROSS JOIN Every combination of rows

JOIN → Combine related data from multiple tables.

SQL Joins Venn Diagram: Inner Join, Left Join, Right Join, and Full Outer Join
Figure 1: Venn diagram representing how Inner, Left, Right, and Full Outer Joins combine records between tables.

Simple Example

Suppose we have:

Employees

emp_id emp_name dept_id
1 Ravi 10
2 Priya 20

Departments

dept_id dept_name
10 IT
20 HR

The common column is dept_id.

SQL
SELECT e.emp_name, d.dept_name
FROM employees e
JOIN departments d
    ON e.dept_id = d.dept_id;

Result:

emp_name dept_name
Ravi IT
Priya HR

The JOIN connects the tables using a related column.


Quick Understanding

TEXT
INNER → Matching
LEFT  → Keep Left
RIGHT → Keep Right
FULL  → Keep Both
SELF  → Same Table
CROSS → Every Combination

Each join type will be explained in the following topics.


Placement Quick Points

  • A JOIN combines data from multiple tables.
  • Tables are usually joined using related columns.
  • INNER JOIN returns matching rows.
  • LEFT, RIGHT, and FULL joins control which unmatched rows are retained.
  • SELF JOIN joins a table to itself.
  • CROSS JOIN creates every possible row combination.

Interview Questions

What is a JOIN?

A JOIN combines related data from two or more tables.

Why are joins needed?

Related data is often stored in separate tables, and joins allow us to retrieve it together.

What are the common types of joins?
TEXT
INNER
LEFT
RIGHT
FULL
SELF
CROSS
What column is commonly used to connect tables?

A related key, such as a primary key and foreign key.


Practice & Hands-On Exercises

Using employees and departments:

  1. Identify the column that connects the two tables.
  2. Write a basic INNER JOIN:
SQL
SELECT e.emp_id, e.emp_name, d.dept_name
FROM employees e
JOIN departments d
    ON e.dept_id = d.dept_id;
  1. Explain the difference between INNER JOIN and LEFT JOIN.
  2. List the six common join types.

💡 Tip: Test your queries using the in-browser interactive runner above.


Key Takeaway

TEXT
TABLE A
   +
TABLE B
   ↓
 JOIN
   ↓
COMBINED DATA

Joins allow SQL to combine related data stored in different tables.

End of What are Joins? (Overview)