Introduction
Join means combine. The join clause is used to combine the data from one and more than one table. Suppose there is more than one table and the user would like to display the data from all tables. In this scenario we will join the table. Let us assume there are two tables: Employee and Branch. From these tables user would like to combine the column from both the tables, then user has to use join.
Types of Join
- Self join
- Left outer join
- Right outer join
- Inner join
Before discussing join we will see the steps to work with joins in SQL Server.
Step 1: Go to Start button and select SQL Server Management Studio as in the following figure:
Now click on SQL Server Management Studio and go to object explorer.
Step 2: Create a new database using the following:
Create database database_Name
In this discussion I have created a database with name
DBView as in the following figure:
Now go to table and create two tables,
- Employee
- Branch
Create table employee with four columns as:
- create table Employee(eid int primary key,ename varchar(20),designation varchar(20),mgrid int)
Now insert the values in table Employee:
- insert into Employee values(1,'Sandeep','DBA',2)
- insert into Employee values(2,'Rakesh','.Net Developer',1)
- insert into Employee values(3,'sohan','Java Developer',1)
- insert into Employee values(4,'Suresh','Software Trainee',3)
- insert into Employee values(5,'Mohan','Software Trainee',4)
After inserting the data in table run the query.
Now output will be as in the following figure:
Again create one more table with name Branch.
Create table Branch.
Now insert the values in table branch:
- insert into branch values(1oo,'Hyd',1)
- insert into branch values(1o1,'DEL',2)
- insert into branch values(1o3,'Bag',3)
- insert into branch values(1o4,'Chn',4)
- insert into branch values(1o5,'Nod',5)
Now run the query:
Output will be displayed as in the following figure:
After completing the database and table work we will start working with Joins, which will be in next article of the series.