Join:
Join clause use to combine the data from one and more than one table.. Suppose there is a company in this company there is more than 2 departments and management people of this company would like to display the data from both table at a time. In this case back end developer we will be create one join. For better understanding we will create two tables as EmployeeDetails and Department in database like.
- create table Empdetails
- (
- eid int Primary key,ename varchar(20),Designation varchar(20),Salary int
- )
- create table Department
- (
- Did int,DName varchar(20),eid int foreign key references Empdetails(eid)
- )
Inserting values in Database
- Insert into Empdetails values
- (
- 1,’Sandeep’,’S/w Dev.’,25000
- )
- Insert into Department values
- (
- 101,’Development’,1
- )
Figure: EmployeeDetails table
Figure: Department table
Now back end developer will be create one joins by using following syntax.
Syntax:
- Select columns name
- From Left side table name
- Joins type Right side table name
- On condition
Sample Example :
- select ename,Designation,did,dname
- from EmpDetails
- inner join Department
- on EmpDetails.eid=department.eid
Above view Query will display the data as,
Figure: JoinsData
Point to Remember: Joins clause use to combined the data from one and more than one tables. There are types of Joins and these are: - Inner Join
- Left outer join
- Right outer join
- Cross join
Syntax for join
- Select column name
- From table name//Left side table name
- Join type table name//Right side table name
- On condition
Sample Example for join
- select ename,Designation,did,dname
- from EmpDetails //EmpDetails is left side table
- inner join Department // Department is Right side table
- on EmpDetails.eid=department.eid