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
 General SQL Server Forums
 New to SQL Server Programming
 Join Problem

Author  Topic 

youruseridistoxic
Yak Posting Veteran

65 Posts

Posted - 2009-03-31 : 08:12:07
I'm running into an issue whereby records are being omitted from the resultset. I'm slowly but surely gaining a better understanding of the join types out there, but it seems no matter which I use - the resultset is the same.

select tk.first+' '+tk.last as [CompleteName], tk.ID, userid.udvalue as [NetworkID], tk.email, telext.udvalue as [PrimaryPhone]
from timer tk
inner join udf userid
on tk.ID = userid.udjoin
left outer join udf telext
on tk.ID = telext.udjoin
where userid.udfindex = '3'
and telext.udfindex = '2'
and tk.termdate is null


The current resultset looks like this;

Joe Smith 0014 jsmith jsmith@email.com 8514

More specifically, it is omitting records where telext.udvalue = NULL, which I assume would look like this;

Jane Smith 0022 jasmith jasmith@email.com NULL

What I find truly strange is there ARE records in the resultset that look like this;

Alison Jones 6965 NULL ajones@email.com NULL

The last example kind of makes me wonder if its not the join type at all...but rather the AND operator being used to limit the results to udfindex = 2 and 3.

Given the expected result set, how can I include records from dbo.UDF where no record exists for UDFINDEX = 2, or UDFINDEX = 3 ???

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2009-03-31 : 08:15:56
It would be much easier to answer this question if we had some table definitions, sample data, and desired output. Follow the first link in my signature to see how to provide this.

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL or How to sell Used Cars
For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -