INNER JOIN
JOINs are the heart of relational databases. INNER JOIN is the most common — expect 3–4 JOIN questions in every data analyst interview.
What is an INNER JOIN and when do you use it?
SELECT e.name, d.department_name
FROM employees e
INNER JOIN departments d
ON e.department_id = d.id;INNER JOIN returns only rows where the ON condition matches in BOTH tables. Rows with no match in either table are excluded.
Join employees with their department names and filter for salary > 50000.
SELECT e.name, e.salary, d.department_name
FROM employees e
INNER JOIN departments d
ON e.department_id = d.id
WHERE e.salary > 50000
ORDER BY e.salary DESC;You can add WHERE, ORDER BY, and other clauses after the JOIN. Always alias table names (e, d) when joining to avoid ambiguity.
Find employees along with their manager name (both from same employees table).
SELECT e.name AS employee,
m.name AS manager
FROM employees e
INNER JOIN employees m
ON e.manager_id = m.id;This is a SELF JOIN — joining a table to itself. Used when hierarchical data (manager-employee) is in the same table. Very common interview question.
Join orders, customers, and products tables to get order details.
SELECT o.order_id,
c.customer_name,
p.product_name,
o.quantity
FROM orders o
INNER JOIN customers c ON o.customer_id = c.id
INNER JOIN products p ON o.product_id = p.id;You can chain multiple JOINs. Each JOIN adds another table. The order of JOINs matters for readability but not (usually) for correctness.
Count the number of employees in each department using a JOIN.
SELECT d.department_name,
COUNT(e.id) AS emp_count
FROM departments d
INNER JOIN employees e
ON d.id = e.department_id
GROUP BY d.department_name
ORDER BY emp_count DESC;Combining JOIN with GROUP BY is extremely common in reporting queries. Notice departments with no employees won't appear — use LEFT JOIN if you need them.
What is the difference between JOIN and INNER JOIN?
-- These are identical — JOIN defaults to INNER JOIN:
SELECT * FROM a JOIN b ON a.id = b.id;
SELECT * FROM a INNER JOIN b ON a.id = b.id;JOIN without a type keyword is always INNER JOIN. Writing INNER JOIN explicitly is better practice for readability.
EVIKA ACADEMY · SQL FOR DATA ANALYTICS
Want to master SQL with live practice?
Join our SQL for Data Analytics course — live classes in Noida and online across India.
Book Free Demo Class →