SQL Keyword - INNER JOIN

INNER JOIN Keyword

The INNER JOIN keyword is used to combine two tables based on a common column, and select records that have matching values in these columns.

In the inner join query, each row of Table 1 is compared with each row of Table 2 based on the join condition. If the condition is met, the column values from both tables are combined to form a single row. 

Syntax

SELECT * FROM <TABLE1>
INNER JOIN <TABLE2> ON <TABLE1>.<COLUMN_NAME>=<TABLE2>.<COLUMN_NAME>

Example 1

SELECT * FROM Employee
INNER JOIN Department ON Employee.Dept_Id = Department.Dept_Id

In the above example, if you do not specify the columns for display, it will give you both table values.

Example 2

SELECT E.*,D.Dept_Name FROM Employee E
INNER JOIN Department D ON E.Dept_Id = D.Dept_Id

In the above example, we display all values from the employee table and only one column from the department table.

Summary

The INNER JOIN keyword returns rows that have matching values in both tables.