Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 diff b/w inner and outer joins

Author  Topic 

azhar
Starting Member

1 Post

Posted - 2003-01-31 : 08:27:53
plz tell me the difference between inner and outer join queries. I Know both queries are used for multiple tables but when we use inner join query and when we use outer join query.

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2003-01-31 : 09:13:46
Inner Join also know as equi-join will result in two sets being combined based on criteria specified in the ON clause. The result will be a set where only the members that have matching ON critearia in boths sets are returned.

OUTER JOINS, (LEFT, RIGHT, FULL)
If a set is a subset of another or both contain subsets of each other then an outer join can provide which members are in both or in only ony table.

A Left outer join will combine all results of the first set (left) with the matching results of the second set and assign nulls where there is no matching member from the second (right) set.

A Right outer join is the opposite and combines all results from the right and the matching ones from the left.

A Full outer join is the equivalent of a union of left and right joins where it will create a resulting set which might have some members with information from the left set, some with information from the right set and some with both.

CROSS JOIN OR CARTESIAN PRODUCT
Given two sets a cross join will produce a combination of each member in both sets. Ex:


Set 1 Set 2 Result
A 1 A 1
B 2 A 2
C 3 A 3
B 1
B 2
B 3
C 1
C 2
C 3


The result will contain n*m members where n is the number of members in set 1 and m is the number of members in set 2

BOL has some more examples.




Edited by - ValterBorges on 01/31/2003 09:16:04
Go to Top of Page
   

- Advertisement -