ADVERTISEMENT

SQL INNER JOIN

INNER JOIN combines rows from two or more tables only when matching values exist in both.

🔹 Basic Syntax

SELECT columns
FROM table1
INNER JOIN table2
  ON table1.common_column = table2.common_column;

🔹 Example: Employees and Departments

SELECT
  e.employee_name,
  d.department_name
FROM employees e
INNER JOIN departments d
  ON e.department_id = d.department_id;

✅ This returns only those employees who are assigned to a department.

🔹 Join on Multiple Conditions

SELECT *
FROM orders o
INNER JOIN customers c
  ON o.customer_id = c.customer_id
  AND o.region = c.region;

🔹 Using Table Aliases (Best Practice)

Shortens query and improves readability:

SELECT e.name, d.name
FROM employees e
INNER JOIN departments d
  ON e.dept_id = d.id;

🧠 Quick Recap

Key PointExplanation
INNER JOINReturns only rows with matching values in both tables
ON clauseDefines the join condition
Table aliasesImprove clarity and simplify column references
FiltersCan be combined with WHERE, GROUP BY, etc.

🔗 Use INNER JOIN to extract meaningful data from related tables

ADVERTISEMENT