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)
 Left Join

Author  Topic 

strikeuk
Starting Member

2 Posts

Posted - 2008-03-06 : 09:18:57
Hi guys, need some help with the following, assuming i have the following two tables


Table1
CustomerNo CustomerName
1 ABC
2 XYZ
3 QWE

Table2
DocNo CustomerNo Paid
8000001 2 Y
8000002 1 Y
8000003 1 Y
8000004 3 N
8000005 4 Y


and the following sql script

select CustomerName,DocNo
from table2 left join table1
on table2.CustomerNo = table1.CustomerNo
and paid = 'Y'

why am i still getting five rows of records instead of just four? As i understand it will pull out all the rows from table2 irregardless of whether there are any matching records in table1, but i've already included the condition to only pick "Y" but it's still pulling out all the records.

i need to pull out the info based on the following condition

1)customer already paid
2)doesn't care whether the customer number is in or not

meaning to say i need to pull out all the transactions even if the customer number doesn't exist in the customer table but it has to have the condition of already being paid.
Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-06 : 09:47:53
Try:-
select CustomerName,DocNo
from table2 left join table1
on table2.CustomerNo = table1.CustomerNo
Where paid = 'Y'
Go to Top of Page
   

- Advertisement -