all groups > sql server programming > june 2003 >
You're in the

sql server programming

group:

Returning results where the match is not always there!!!



Returning results where the match is not always there!!! Edgardo Valdez
6/30/2003 2:20:51 PM
sql server programming: Mark:

You can do:

select e-mail_address, [everything else you want]
from tbl1
left join tbl2
on tbl1.Account_Number = tbl2.Account_Number

The matches that don't have e-mail addresses will return
null.

[quoted text, click to view]
Re: Returning results where the match is not always there!!! Aaron Bertrand - MVP
6/30/2003 5:13:03 PM
You could use a LEFT JOIN


SELECT t1.title, t1.name, t1.address,
t1.[account number], t2.[e-mail address]
FROM table1 t1 LEFT JOIN table2 t2
ON t1.[account number] = t2.[account number]


The e-mail address column should be null when there is no valid e-mail
address in table2...





[quoted text, click to view]

Returning results where the match is not always there!!! Sh0t2bts
6/30/2003 10:08:43 PM
Hi All

I have two tables that I need to match customer data on.
The first table holds all of the customers billing info

Title
Name
Address
Account Number

The second holds amongst other things the customer e-mail address, dont ask
why they are seperate it's not my database,

Account number
e-mail address
etc
etc

In my where statment I match on the account number as that is the only thing
they have in common, "Where tbl1.Account_Number = tbl2.Account_Number) but
not everyone has an e-mail address.

I only get results where there is a true match, how can I say (select
e-mail_address Where tbl1.Account_Number = tbl2.Account_Number) but if there
is no match still return the results from the first table??


Hope this makes sence

Mark :o)

Re: Returning results where the match is not always there!!! Sh0t2bts
6/30/2003 10:31:26 PM
Thank You,

This is a great help :o)


[quoted text, click to view]

AddThis Social Bookmark Button