Inner Join with example
It will return only the matching records of both the table.Syntax :
Select Column_Name1,Column_Name2
from Table1
Inner join Table2
On table1.column_name = table2.column_name
consider the following two tables : Salary:
| Emp_id | Emp_salary | Emp_desig |
|---|---|---|
| 01 | 25000 | Software Eng |
| 02 | 30000 | Senior Software Eng |
| 03 | 25000 | Software Analyst |
Employee_detail:
| Emp_id | Emp_city | Emp_gender |
|---|---|---|
| 01 | Pune | Male |
| 02 | Delhi | Female |
| 03 | Noida | Male |
| 04 | Gurgaon | Female |
Query for inner Join Select *
from Salary Inner join Employee_detail
on salary.Emp_id = Employee_detail.Emp_id
Result :
| Emp_id | Emp_salary | Emp_desig | Emp_id | Emp_city | Emp_gender |
|---|---|---|---|---|---|
| 01 | 25000 | Software Eng | 01 | Pune | Male |
| 02 | 30000 | Senior Software Eng | 02 | Delhi | Female |
| 03 | 25000 | Software Analyst | 03 | Noida | Male |
Left Join with example
All the records of first table will appear & only matching record of second table will appear.Syntax :
Select Column_Name1,Column_Name2
from Table1
Left join Table2
On table1.column_name = table2.column_name
consider the following two tables : 1.Salary:
| Emp_id | Emp_salary | Emp_desig |
|---|---|---|
| 01 | 25000 | Software Eng |
| 02 | 30000 | Senior Software Eng |
| 03 | 25000 | Software Analyst |
2.Employee_detail:
| Emp_id | Emp_city | Emp_gender |
|---|---|---|
| 01 | Pune | Male |
| 02 | Delhi | Female |
Query for inner Join Select *
from Salary
Left join Employee_detail
on salary.Emp_id = Employee_detail.Emp_id
Result :
| Emp_id | Emp_salary | Emp_desig | Emp_id | Emp_city | Emp_gender |
|---|---|---|---|---|---|
| 01 | 25000 | Software Eng | 01 | Pune | Male |
| 02 | 30000 | Senior Software Eng | 02 | Delhi | Female |
| 03 | 25000 | Software Analyst | NULL | NULL | NULL |
Right Join with example
All the records of second table will appear & only matching record of first table will appear.Syntax :
Select Column_Name1,Column_Name2
from Table1
Right join Table2
On table1.column_name = table2.column_name
consider the following two tables : 1.Salary:
| Emp_id | Emp_salary | Emp_desig |
|---|---|---|
| 01 | 25000 | Software Eng |
| 02 | 30000 | Senior Software Eng |
| 03 | 25000 | Software Analyst |
2.Employee_detail:
| Emp_id | Emp_city | Emp_gender |
|---|---|---|
| 01 | Pune | Male |
| 02 | Delhi | Female |
| 03 | Noida | Female |
| 04 | Gurgaon | Male |
Query for right Join Select *
from Salary
right join Employee_detail
on salary.Emp_id = Employee_detail.Emp_id
Result :
| Emp_id | Emp_salary | Emp_desig | Emp_id | Emp_city | Emp_gender |
|---|---|---|---|---|---|
| 01 | 25000 | Software Eng | 01 | Pune | Male |
| 02 | 30000 | Senior Software Eng | 02 | Delhi | Female |
| 03 | 25000 | Software Analyst | 03 | Noida | Female |
| Null | Null | Null | 04 | Gurgaon | Male |
No comments:
Post a Comment