Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to use outer join in SQL server

Status
Not open for further replies.

h3nd

Programmer
Joined
Jul 1, 2006
Messages
147
Location
AU
Hi guys,

I was just wondering how to use 'outer join' in SQL SERVER. I've tried this one, but I don't think it's working.

Code:
select ldn.* 
from dbo.ldnfund ldn
right outer join dbo.nyfund ny 
on ldn.Ccy = ny.Ccy

Any help ??
Thanks guys
 
What do you mean it isn't working? How you now that if you get only fields from ldnfund in result set?
Code:
select *
from dbo.ldnfund ldn
right outer join dbo.nyfund ny
on ldn.Ccy = ny.Ccy

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Yeah,

the table in ldnfund actually has more compare to nyfund. So I wanna find the records that exist in table "ldnfund" but not exist in "nyfund". That's all.

But in my first query, they came up with all records in ldnfund. I tried inner join, it worked, but not for the outer join.

 
Do you not want a LEFT outer join in this case?

Fee

The question should be [red]Is it worth trying to do?[/red] not [blue] Can it be done?[/blue]
 
Code:
select *
from dbo.ldnfund ldn
LEFT join dbo.nyfund ny
on ldn.Ccy = ny.Ccy
WHERE ny.Ccy IS NULL

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
That's what I meant. Thanks Boris - got called away and didn't have time to add it in.

Fee

The question should be [red]Is it worth trying to do?[/red] not [blue] Can it be done?[/blue]
 
RIGHT OUTER JOIN is logically equivalent to LEFT OUTER JOIN, and many people make it a habit never to use RIGHT OUTER JOINs, ever

boris, i would return columns only from the left table if you're looking for unmatched rows...
Code:
select [b]ldn.*[/b]
  from dbo.ldnfund ldn
left outer
  join dbo.nyfund ny
    on ny.Ccy = ldn.Ccy
 where ny.Ccy is null

r937.com | rudy.ca
 
Hi Boris,

Thanks your coding is working great.

r937,

I've tried change left to right, but the result was not the same.
The result returns with no rows.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top