SQL JOIN

 JOINS IN SQL SERVER

I am going to explain various type of join in SQL server  like  Inner  Join ,cross join , Left Outer Join, Right Outer Join, Full Outer Join, Equi  Join ,Hash Join.

 

Before going to join discussion first I am going to create two table . One is Employee   another one is Location.

Employee :

 

EmpId First Name Last Name DOJ Location ID
1 Alok Kumar 2001-01-01 00:00:00.000 1
2 Rahul Raj 2002-08-12 00:00:00.000 1
3 Pankaj Raj 1999-09-01 00:00:00.000 2

 

Location:

 

Location ID Street City State
1 545 Pike Delhi KR
2 222 Gama Bangalore DL
3 Bank Street Kolkatta WB

 

 

 

  1. INNER Join :-

The join that display only those record that have a match in  both joined table is known as inner join. This is default join.

Syntax:

SELECT a1.column_name,a2.column_name

FROM table1  a1

INNER JOIN table2 a2

On a1.colum_name=a2.column_name

 

Example:

select   A.FirstName,L.Street from   Employee  as A

inner join Location L

on a.LocationID=l.LocationID

 

Output:

FirstName Street
Alok Delhi
Rahul Delhi
Pankaj Banglore
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s