INNER JOIN in MySQL

Rumman Ansari   Software Engineer   2024-06-11 10:51:37   12 Share
Subject Syllabus DetailsSubject Details
☰ Table of Contents

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.

  • employees table:

  • departments table:

Query:

Result:

 

Example 2: Inner Join with Multiple Conditions

Assume we have two tables: orders and customers.

  • orders table:

  • customers table:

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.

  • orders table:

  • customers table:
  • products table:

Query:

Result: