C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Interview   Jobs   Projects   Offshore Development    
Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing | Talk to Us |



My Profile

Gifts

Active Members
TodayLast 7 Days more...







Joins in Sql Server


Posted Date: 25 Jun 2008    Resource Type: Articles    Category: Databases

Posted By: Sriram       Member Level: Gold
Rating:     Points: 8



Joins in Sql Server:

Joins actualy Performs Two or more Tables combined into a single result set.
Joins can also fetch with different dataBase,different Server also.

There are 5 types of joins available in sql server

1) inner join
2) outer join( left outer join,Right outer join)
3) Full Join
4) Cross Join
5) Self Join

1) inner Join : Two tables having the common column values go with inner join.

Example:
select * from emp inner join empsalary
on
emp.empid=empsalary.empid

2) outer join:
Outer join has two sub types left outer join,Right outer join
Left outer join: Taking Left side values of the table checking into right side
select * from emp left outer join empsalary
on emp.empid=empsalary.empid
Right Outer join:Taking Right side values of the table checking left side
select * from emp right outer join empsalary
on emp.empid=empsalary.empid

3) Full join :
Full join is combined with left outer join ,Right outer join.
select * from emp full join employee
on emp.empid=employee.empid

4) cross Join: cross join is an carteasion product ,its like matrix format here it wont come on condidtion

select * from emp cross join employee

Self join :

Self join can check within the table called self join.








Responses

Author: Satyanarayan SushilKumar Bajoria    27 Jun 2008Member Level: Gold   Points : 2
Hi,

Nice attempy to explain Join in SQL Server.

If possible explain outer join in brief,you didn't mention anything on outer join.
And also if possible give eample for self join.

Keep posting.

Thanks for sharing your knowledge.

Thanks and Regards
S.S.Bajoria


Author: Sriram    30 Jun 2008Member Level: Gold   Points : 2
joins in sql server
Inner join
Outer join(left outer join,Right outer join)
Full outer Join
Cross join

create table emps(empid int,empname varchar(34))
insert into emps values(103,'ramesh')

create table employee(empid int,salary money)
insert into employee values(104,6000)
select * from emps
select * from employee

inner join:
select * from emps inner join employee on
emps.empid=employee.empid

empid empname empid salary
----------- ---------------------------------- ----------- ---------------------
101 sriram 101 3000.0000
102 ganesh 102 4000.0000

(2 row(s) affected)

left outer join :
select * from emps left outer join employee on
emps.empid=employee.empid
empid empname empid salary
----------- ---------------------------------- ----------- ---------------------
101 sriram 101 3000.0000
102 ganesh 102 4000.0000
103 ramesh NULL NULL

(3 row(s) affected)


right outer join
select * from emps right outer join employee on
emps.empid=employee.empid

empid empname empid salary
----------- ---------------------------------- ----------- ---------------------
101 sriram 101 3000.0000
102 ganesh 102 4000.0000
NULL NULL 104 6000.0000
full join :
select * from emps full outer join employee on
emps.empid=employee.empid

empid empname empid salary
----------- ---------------------------------- ----------- ---------------------
101 sriram 101 3000.0000
102 ganesh 102 4000.0000
103 ramesh NULL NULL
NULL NULL 104 6000.0000

cross join:
select * from emps cross join employee
empid empname empid salary
----------- ---------------------------------- ----------- ---------------------
101 sriram 101 3000.0000
102 ganesh 101 3000.0000
103 ramesh 101 3000.0000
101 sriram 102 4000.0000
102 ganesh 102 4000.0000
103 ramesh 102 4000.0000
101 sriram 104 6000.0000
102 ganesh 104 6000.0000
103 ramesh 104 6000.0000


To Join different DataBase :

select * from master.dbo.emps inner join msdb.dbo.employee on
master.dbo.emps.empid=msdb.dbo.employee.empid




Author: UltimateRengan    30 Jun 2008Member Level: Diamond   Points : 1
This is very good information,Continue posting such useful articles.



Author: Anne Grace    23 Jul 2008Member Level: Silver   Points : 0
good one.keep going


Author: deepakyadav    23 Jul 2008Member Level: Bronze   Points : 0
thank u this really helps me pal


Author: deepakyadav    23 Jul 2008Member Level: Bronze   Points : 0
if possible can u please give me some more details on stored procedures


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Nested Trigger or Recursing Trigger in SQL Server
Previous Resource: creating a database
Return to Discussion Resource Index
Post New Resource
Category: Databases


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use