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
 General SQL Server Forums
 New to SQL Server Programming
 SQL Join Statements

Author  Topic 

Azimuth
Starting Member

1 Post

Posted - 2012-06-11 : 09:26:05
Hello all, I have a small question on the functionality of different join statements, and I was hoping the community could help me.
At work, I was recently touching on some of our SQL statements to get information from our database and after getting help we found out it was because we were using a left join instead of an outter join.

I was curious if someone could explain the difference between these two, and maybe even the rest such as inner, and right joins. Thanks in advance.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-06-11 : 10:16:45
inner join: return only records if both tables have matching records

left outer join: return all records from first table and if there is no match in second table then return NULL for all columns from second table
right outer join: return all records from second table and if there is no match in first table then return NULL for all columns from first table

full outer join: return all records and do that NULL stuff for each the left or right table...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-06-11 : 10:20:13
Note there there is no difference between these statements

JOIN
INNER JOIN

And
[code]
LEFT JOIN
LEFT OUTER JOIN
[code]
Basically INNER and OUTER are inferred....

Transact Charlie
Msg 3903, Level 16, State 1, Line 1736:
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION

http://nosqlsolution.blogspot.co.uk/
Go to Top of Page
   

- Advertisement -