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)
 Having trouble with a join

Author  Topic 

Munchausen
Starting Member

25 Posts

Posted - 2005-10-18 : 11:40:05
I'm having a problem with a join.

Table1 has a record number column, and so does Table2. Not every record number in Table1 exists in Table2, but many do.

I'm trying to display all of the records in Table1, with some columns from Table2.

I've tried:

select t1.recordno, t2.columname
from Table1 t1 left outer join Table2 t2
on t1.recordno = t2.recordno

Unfortunately, this is only returning rows for records that exist in Table 1 and Table2 (t2.columname is never null), but I want it to display all records from Table1, even if they don't have a corresponding record number in Table2.

Any help would be greatly appreciated.

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2005-10-18 : 12:03:30
Your query is correctly formatted to display all records from Table1, along with any corresponding records from Table2. So something else fishy is going on...
Go to Top of Page

r937
Posting Yak Master

112 Posts

Posted - 2005-10-18 : 12:05:10
i bet you also have a WHERE condition on some column in table 2

move this condition to the ON clause

rudy
http://r937.com/
Go to Top of Page
   

- Advertisement -