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.
Author |
Topic |
ganeshkumar08
Posting Yak Master
187 Posts |
Posted - 2009-06-12 : 06:30:47
|
Hi All,Below is my sample table, data and queryDeclare @N Table(RECP_ID Int,TimeStamp_ID Int)Declare @T Table(RECP_ID Int,TimeStamp_ID Int)Insert Into @NSelect 17274267,151636 union allSelect 17274268,151638 union allSelect 17274269,151639 union allSelect 17274270,151641 union allSelect 17274272,151643 union allSelect 17274267,151645 union allSelect 17274269,151646 union allSelect 17274270,151647 union allSelect 17274272,151648Insert Into @TSelect 17274267,151636 Union AllSelect 17274268,151638 Union AllSelect 17274269,151639 Union AllSelect 17274270,151641 Union AllSelect 17274272,151643 Union AllSelect 17274267,151645 Union AllSelect 17274269,151646 Union AllSelect 17274270,151647 Union AllSelect 17274272,151648Select N.Recp_ID From @N NInner Join @T T On T.TimeStamp_ID <> N.TimeStamp_ID And T.Recp_ID = N.RECP_IDIf i run the abouve query i get below as outputRecp_ID-------1727426717274269172742701727427217274267172742691727427017274272But 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.ThanksGaneshSolutions 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 TRANcreate Table N(RECP_ID Int,TimeStamp_ID Int)create Table T(RECP_ID Int,TimeStamp_ID Int)Insert Into NSelect 17274267,151636 union allSelect 17274268,151638 union allSelect 17274269,151639 union allSelect 17274270,151641 union allSelect 17274272,151643 union allSelect 17274267,151645 union allSelect 17274269,151646 union allSelect 17274270,151647 union allSelect 17274272,151648Insert Into TSelect 17274267,151636 Union AllSelect 17274268,151638 Union AllSelect 17274269,151639 Union AllSelect 17274270,151641 Union AllSelect 17274272,151643 Union AllSelect 17274267,151645 Union AllSelect 17274269,151646 Union AllSelect 17274270,151647 Union AllSelect 17274272,151648Select N.Recp_ID,T.Recp_ID, N.TimeStamp_ID,T.TimeStamp_ID From N NInner Join T T On T.Recp_ID = N.RECP_ID and T.TimeStamp_ID <> N.TimeStamp_IDROLLBACK No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
ganeshkumar08
Posting Yak Master
187 Posts |
Posted - 2009-06-12 : 07:48:41
|
I got answer, Thanks for your replySelect N.Recp_ID From N NInner 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 |
|
|
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.GreetingsWebfred No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
|
|
|
|
|