Hackforge Academy

Category: sql

why we need join in sql

Published on 24 May 2026

Explanation

JOIN is used in SQL to combine data from multiple tables based on a related column.

Code:

SELECT employees.name, 
departments.department_name FROM 
employees JOIN departments 
ON employees.department_id = departments.id;

Explanation

Without JOIN, related data stored in separate tables cannot be fetched together in a single query.

Code:

SELECT orders.order_id, 
customers.customer_name 
FROM orders JOIN customers 
ON orders.customer_id = customers.id;

Explanation

JOIN helps maintain database normalization by storing related data in different tables while still allowing combined retrieval.

Code:

SELECT students.name, courses.course_name 
FROM students JOIN enrollments 
ON students.id = enrollments.student_id JOIN
 courses ON enrollments.course_id = 
courses.id;

Explanation

JOIN improves data organization and reduces duplicate data in databases.

Code:

SELECT products.product_name, 
categories.category_name FROM 
products JOIN categories ON 
products.category_id = categories.id;

Explanation

Different types of JOINs are used for different scenarios such as INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN.

Code:

SELECT employees.name, 
departments.department_name FROM 
employees LEFT JOIN 
departments ON employees.department_id = 
departments.id;

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community