SQL JOINs Explained – INNER JOIN, LEFT JOIN and RIGHT JOIN
Published: 05 Nov, 2026 | Author: CCI Admin | Category: SQL / Database
In a database, information is often stored in separate tables. For example, a college database may store student details in one table and course details in another table. SQL JOINs help us combine related information from these tables and display it as a single result.
In this blog, let us learn about INNER JOIN, LEFT JOIN, and RIGHT JOIN with simple examples and outputs.
1. What Is a SQL JOIN?
A SQL JOIN is used to combine rows from two or more tables based on a related column. The related column is commonly a primary key in one table and a foreign key in another table.
Common SQL JOIN types include:
- INNER JOIN
- LEFT JOIN
- RIGHT JOIN
- FULL OUTER JOIN
In this blog, we will focus on INNER JOIN, LEFT JOIN, and RIGHT JOIN.
2. Sample Database Tables
Let us use two tables to understand how JOINs work.
Students Table
| StudentID | StudentName |
|---|---|
| 1 | Arun |
| 2 | Priya |
| 3 | Kavin |
Enrollments Table
| EnrollmentID | StudentID | CourseName |
|---|---|---|
| 101 | 1 | Python |
| 102 | 2 | Java |
| 103 | 1 | SQL |
Notice that Kavin has no enrollment record. We will use this example to understand how LEFT JOIN works.
3. INNER JOIN – Return Matching Records
INNER JOIN returns only the rows that have matching values in both tables. If a student does not have an enrollment record, that student will not appear in the result.
SQL Query
SELECT
Students.StudentName,
Enrollments.CourseName
FROM Students
INNER JOIN Enrollments
ON Students.StudentID = Enrollments.StudentID;
Output
| StudentName | CourseName |
|---|---|
| Arun | Python |
| Priya | Java |
| Arun | SQL |
Remember: INNER JOIN returns only matching records.
4. LEFT JOIN – Return All Records from the Left Table
LEFT JOIN returns all rows from the left table and matching rows from the right table. If there is no match, the columns from the right table contain NULL values.
SQL Query
SELECT
Students.StudentName,
Enrollments.CourseName
FROM Students
LEFT JOIN Enrollments
ON Students.StudentID = Enrollments.StudentID;
Output
| StudentName | CourseName |
|---|---|
| Arun | Python |
| Priya | Java |
| Kavin | NULL |
| Arun | SQL |
Kavin appears in the result even though he has no enrollment record. His CourseName is displayed as NULL.
Remember: LEFT JOIN keeps every row from the left table.
5. RIGHT JOIN – Return All Records from the Right Table
RIGHT JOIN returns all rows from the right table and matching rows from the left table. If there is no match, the columns from the left table contain NULL values.
SQL Query
SELECT
Students.StudentName,
Enrollments.CourseName
FROM Students
RIGHT JOIN Enrollments
ON Students.StudentID = Enrollments.StudentID;
Output
| StudentName | CourseName |
|---|---|
| Arun | Python |
| Priya | Java |
| Arun | SQL |
In this example, every enrollment has a matching student. Therefore, RIGHT JOIN returns the same rows as INNER JOIN.
Remember: RIGHT JOIN keeps every row from the right table.
6. Difference Between INNER JOIN, LEFT JOIN and RIGHT JOIN
| JOIN Type | Purpose |
|---|---|
| INNER JOIN | Returns matching rows from both tables. |
| LEFT JOIN | Returns all left-table rows and matching right-table rows. |
| RIGHT JOIN | Returns all right-table rows and matching left-table rows. |
7. Real-Life Uses of SQL JOINs
- Display student names along with their course details.
- Display customer information along with their orders.
- Retrieve employee details along with department names.
- Combine product information with sales records.
- Find records that do not have matching data in another table.
8. Frequently Asked Questions (FAQ)
What is the purpose of a SQL JOIN?
A SQL JOIN combines related data from two or more tables using a matching column.
What is the difference between INNER JOIN and LEFT JOIN?
INNER JOIN returns only matching records. LEFT JOIN returns every row from the left table, including rows without a match.
What does NULL mean in a JOIN result?
NULL indicates that no matching value was found for that column in the other table.
Can we join more than two tables?
Yes. SQL allows multiple JOIN operations in one query to combine data from several related tables.
Is RIGHT JOIN the same as LEFT JOIN?
They are similar, but they preserve different tables. LEFT JOIN preserves the left table, while RIGHT JOIN preserves the right table.
9. Practice Tasks for Students
- Display student names and course names using INNER JOIN.
- Display all students, including students without enrollments, using LEFT JOIN.
- Display all enrollment records using RIGHT JOIN.
- Create Customers and Orders tables and combine them using JOIN.
- Find students who have not enrolled in any course.
Conclusion
SQL JOINs are essential for working with relational databases. INNER JOIN retrieves matching records, LEFT JOIN preserves all records from the left table, and RIGHT JOIN preserves all records from the right table.
By practicing these JOIN types, beginners can write better SQL queries and work confidently with real-world database projects.
At CCI Computer Education, students can strengthen their database and programming skills through practical examples, coding exercises, and projects.
Related CCI Blogs
- Introduction to MySQL
- Basic SQL Queries
- SQL SELECT, WHERE and ORDER BY Commands
- Primary Key and Foreign Key Explained
Contact CCI Computer Education – Pudukkottai
Want to learn SQL, database management, and programming? Contact CCI Computer Education to improve your technical skills.
Call: 98427 97945
Website:
ccipudukkottai.com
WhatsApp Channel:
Follow CCI on WhatsApp
CCI Computer Education – Learn Today, Build Tomorrow.