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)
 The Last x number of Records

Author  Topic 

Xerxes
Aged Yak Warrior

666 Posts

Posted - 2005-02-15 : 10:58:44
Did a search, but found no answer to this...

To get the first 47 records of a given table I can do this:
SELECT TOP 47 * FROM tab_Work

...the question is: How do I get the LAST 47?



Semper fi, Xerxes, USMC(Ret.)
-------------------------------------------------------------------------
Once a Marine Programmer Analyst ALWAYS a Marine Programmer Analyst

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-02-15 : 11:11:03
SELECT TOP 47 * FROM tab_Work order by someCol desc

you do know that order of data in a table isn't guaranteed, no?

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Xerxes
Aged Yak Warrior

666 Posts

Posted - 2005-02-15 : 11:16:38
Mladen

....I know this much: in the IT world NOTHING is GUARANTEED.

Thanks again!



Semper fi, Xerxes, USMC(Ret.)
-------------------------------------------------------------------------
Once a Marine Programmer Analyst ALWAYS a Marine Programmer Analyst
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2005-02-15 : 15:32:14
>>> you do know that order of data in a table isn't guaranteed, no? <<<

Xerxes is a Senior Database Analyst... Of course he knows that!!!

HTH

=================================================================
Egotism is the anesthetic that dulls the pain of stupidity. -Frank William Leahy, football coach (1908-1973)
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-02-15 : 15:33:59
it was a joke, and i think he got it as such...
don't loose you kool, bustaz.

Go with the flow & have fun! Else fight the flow
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-02-15 : 15:55:26
>>it was a joke, and i think he got it as such...


Actually, I am not sure of this based on his response, to be honest ... Xerxes -- you know that he wasn't joking, right? the order of the data retrieve is NOT gauranteed w/o an explicit ORDER BY clause. there is no such thing as the "last N records" in a table w/o columns that are populated with values that will allow you to determine that.

- Jeff
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-02-16 : 00:40:49

Will this work?

If there is no Identity column then temporarily add that column, select this and drop that column

Declare @end numeric
Declare @Start numeric
Select @end=Max(Id) from table
set @Start= @end-46

select @end,@Start
exec('select * from table where Id between '+@Start+' and '+@end)


Madhivanan
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-02-16 : 12:47:04
quote:
Originally posted by Xerxes

....I know this much: in the IT world NOTHING is GUARANTEED.



Only for some...and I keep the others at bay....



Brett

8-)
Go to Top of Page

Xerxes
Aged Yak Warrior

666 Posts

Posted - 2005-02-16 : 13:19:30
quote:
Originally posted by spirit1

it was a joke, and i think he got it as such...
don't loose you kool, bustaz.

Go with the flow & have fun! Else fight the flow



I go the joke....although, I am puzzled that that my perception of a joke is fodder for discussion!

Semper fi, Xerxes, USMC(Ret.)
-------------------------------------------------------------------------
Once a Marine Programmer Analyst ALWAYS a Marine Programmer Analyst
Go to Top of Page
   

- Advertisement -