SQL Inner Join

The Syntax of the SQL INNER JOIN is given as follows:

SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;

                                                       OR

SELECT column_name(s)
FROM table1
JOIN table2
ON table1.column_name=table2.column_name                                           

                                                      OR

SELECT column_name(s)
FROM table1, table2
ON table1.column_name=table2.column_name;

 

As the INNER JOIN is known as JOIN any of the syntaxes can be used to JOIN the tables.

 

Example:

Let us take two tables:

1.Employee table

Id Employee_Name Empl_Age Monthly package
1 Sushil 22 18000
2 Bhargav 32 45000
3 Mohanthy 26 25000
4 Nithin 38 52000

 

 

2.Payment Table

Payment_ID Date Employee_Id Amount
150 23-02-2016 1 2500
151 30-06-2015 2 5000
152 14-09-2016 4 6500

 


Now to JOIN the tables we write a statement

SELECT Employee_ID,Employee_Name,Emp_Age, Amount
FROM Employee
INNER JOIN Payment
WHERE Employee.ID=Payment.Employee_ID;

 

 

The result produced will be like this:

Employee_ID Employee_Name Emp_Age Amount
1 Sushil 22 2500
2 Bhargav 32 5000
4 Nithin 38 6500