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

Null values in a join 1

Status
Not open for further replies.

robman70

Technical User
Aug 6, 2002
90
I'm having problems with a join again, my sql statement has an inner join:

Code:
select table1.name, table2.user, table3.dest from table1 INNER JOIN table2 on table2.user = table1.uname INNER JOIN table3 on table3.dest = table1.destid

what i want to know is how can i say that sometimes table2.user will be null and if it is just match the other two conditions and return null for table2.user. I hope im being clear i know it may sound a little confusing. i tried:

Code:
select table1.name, table2.user, table3.dest from table1 INNER JOIN table2 on table2.user = table1.uname or is null table2.user INNER JOIN table3 on table3.dest = table1.destid

but it didnt like that

any help appreciated
 
Give us asample of your data inthe two tables and what result you want. Nulls are impossible in a jopin becasue what would they join too? However if what you are trying to do is find the records in table1 which are not in table2 that is possible with a left join.

Questions about posting. See faq183-874
 
Thanks sqlsister, left join was exactly what i needed
 
For what it's worth, you can join columns that have Null values.

You might be able to do it with

SET ANSI_NULLS OFF

And you can definitely do it with

ON IsNull(A.Key,'uniquevalue') = IsNull(B.Key,'uniquevalue')

but these are just hacks and probably shouldn't be used for anything important.


-------------------------------------
A sacrifice is harder when no one knows you've made it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top