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;