INNER JOIN in MySQL
☰Fullscreen
Table of Content:
Inner Join:
- Returns only the rows that have matching values in both tables.
- Syntax:
SELECT columns FROM table1 INNER JOIN table2 ON table1.common_column = table2.common_column;
Below are a few examples of how to use INNER JOIN in MySQL.
Example 1: Simple Inner Join
Assume we have two tables: employees and departments.
-
employeestable: departmentstable:
Query:
Result:
Example 2: Inner Join with Multiple Conditions
Assume we have two tables: orders and customers.
-
orderstable: customerstable:
Query:
Result:
Example 3: Inner Join with Aliases
Using aliases can make queries more readable, especially when dealing with multiple tables.
Query:
Result:
Example 4: Inner Join on Multiple Tables
Assume we have three tables: orders, customers, and products.
-
orderstable: customerstable:productstable:
Query:
Result: