SQL INNER JOIN
INNER JOIN combines rows from two or more tables only when matching values exist in both. πΉ Basic Syntax πΉ Example: Employees and Departments β This returns only those employees who are assigned to a department. πΉ Join on Multiple Conditions πΉ Using Table Aliases (Best Practice) Shortens query and improves readability: π§ Quick Recap […]
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 Point | Explanation |
|---|---|
INNER JOIN | Returns only rows with matching values in both tables |
ON clause | Defines the join condition |
| Table aliases | Improve clarity and simplify column references |
| Filters | Can be combined with WHERE, GROUP BY, etc. |
π Use INNER JOIN to extract meaningful data from related tables
Was this helpful?
Thanks for your feedback!