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
 SQL Server Development (2000)
 Doubt in inner join

Author  Topic 

ganeshkumar08
Posting Yak Master

187 Posts

Posted - 2009-06-12 : 06:30:47
Hi All,

Below is my sample table, data and query

Declare @N Table(RECP_ID Int,TimeStamp_ID Int)
Declare @T Table(RECP_ID Int,TimeStamp_ID Int)

Insert Into @N
Select 17274267,151636 union all
Select 17274268,151638 union all
Select 17274269,151639 union all
Select 17274270,151641 union all
Select 17274272,151643 union all
Select 17274267,151645 union all
Select 17274269,151646 union all
Select 17274270,151647 union all
Select 17274272,151648


Insert Into @T
Select 17274267,151636 Union All
Select 17274268,151638 Union All
Select 17274269,151639 Union All
Select 17274270,151641 Union All
Select 17274272,151643 Union All
Select 17274267,151645 Union All
Select 17274269,151646 Union All
Select 17274270,151647 Union All
Select 17274272,151648

Select N.Recp_ID From @N N
Inner Join @T T On T.TimeStamp_ID <> N.TimeStamp_ID And T.Recp_ID = N.RECP_ID

If i run the abouve query i get below as output

Recp_ID
-------
17274267
17274269
17274270
17274272
17274267
17274269
17274270
17274272

But my actual output should be no rows to be returned.
since no row will satisfy condition in join, then why i am getting output.
Can any one please help me in this. its urgent.

Thanks
Ganesh

Solutions are easy. Understanding the problem, now, that's the hard part

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-12 : 07:32:22
Have a look at my result set.
You can see that each returned row satisfy the condition.
BEGIN TRAN

create Table N(RECP_ID Int,TimeStamp_ID Int)
create Table T(RECP_ID Int,TimeStamp_ID Int)

Insert Into N
Select 17274267,151636 union all
Select 17274268,151638 union all
Select 17274269,151639 union all
Select 17274270,151641 union all
Select 17274272,151643 union all
Select 17274267,151645 union all
Select 17274269,151646 union all
Select 17274270,151647 union all
Select 17274272,151648


Insert Into T
Select 17274267,151636 Union All
Select 17274268,151638 Union All
Select 17274269,151639 Union All
Select 17274270,151641 Union All
Select 17274272,151643 Union All
Select 17274267,151645 Union All
Select 17274269,151646 Union All
Select 17274270,151647 Union All
Select 17274272,151648

Select N.Recp_ID,T.Recp_ID, N.TimeStamp_ID,T.TimeStamp_ID From N N
Inner Join T T On T.Recp_ID = N.RECP_ID and T.TimeStamp_ID <> N.TimeStamp_ID


ROLLBACK



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

ganeshkumar08
Posting Yak Master

187 Posts

Posted - 2009-06-12 : 07:48:41
I got answer, Thanks for your reply

Select N.Recp_ID From N N
Inner Join T On T.Recp_ID = N.RECP_ID
Where N.TimeStamp_ID Not In (Select TimeStamp_ID From @T)



Solutions are easy. Understanding the problem, now, that's the hard part
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-12 : 08:19:11
Ok - not sure about the given solution and what your demand is.
I wanted only to show, that the query did exactly what it should do.

Greetings
Webfred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -