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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

outer self join with where 1

Status
Not open for further replies.

simian336

Programmer
Joined
Sep 16, 2009
Messages
723
Location
US
Any idea why this would not work.

select a.object_id,a.column_id , a.name,
b.object_id,b.column_id, b.name
from sys.columns a
left outer join sys.columns b
on a.column_id = b.column_id
where a.object_id=1109578991
and b.object_id=2130106629

a.object_id=1109578991 has 40 records
and
b.object_id=2130106629 has 39 records

But it is showing 39 matched records and no null.

Shouldn't it match all 40 with 1 on the right being null.

Thanks

Simi
 
your WHERE condition on the "b" table effectively removes the unmatched row

try it like this --
Code:
SELECT a.object_id
     , a.column_id 
     , a.name
     , b.object_id
     , b.column_id
     , b.name
  FROM sys.columns AS a
LEFT OUTER 
  JOIN sys.columns AS b  
    ON b.column_id = a.column_id
   [red]AND[/red] b.object_id = 2130106629
 WHERE a.object_id = 1109578991
:-)

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Thanks Rudy

Worked perfectly...

Simi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top