Thursday, 19 April 2012

How to use in left join ,right join in sql server?


We will  explain what are the Joins in SQL Server and some important  Joins  which is mostly uses in database query as  (left join ,right join in sql with  example) .

It is  joins are used to get data from two or more tables based on relationship between some of the columns in tables. first of all use in  primary key of first table and foreign key of second table to get data from tables by using this relationship i can reduce the duplication of data in every table.



Create database in your system and also create table , field name with datatype and make the primary key in first table .


step 1-pankaj(database name)

step -2 table name1(employee)

step -3 field Name 

ID(primary key,int)

name(varchar)

Address(varchar)

Email_Id(varchar)

Create second table , field name with datatype and make the foriegn key in second table .

table name2(designation)

dep_id(set primary key,int)

id(foriegn key)

department(varchar)

salary(varchar)


Now we can show both table with the help of  join query....

1---Join(Sql command) show both table's record

use pankaj(database name)

select * from employee(table name1) join designation(table2) on employee.id=designation.id



2---Join(show particular record both table's

select employee.name,employee.address,employee.email_id,designation.department,designation.salary

from employee

join

designation

on employee.id=designation.id



what is defferent between right join and left join?

Right Join:-It is taking output all items from right table AND (only) matching items from left table that is called right join.

For Example:-

select * from employee left join designation on employee.id=designation.id



Left Join-It is taking output all items from left table AND (only) matching items from right table

For Example:-
select * from employee left join designation on employee.id=designation.id


No comments:

Post a Comment

What is ASP.NET? Components of ASP.NET

ASP.Net Definition -It is used for creating web-based applications.ASP.Net is a web development platform provided by Microsoft. ASP.NET i...