|
-
Feb 5th, 2002, 11:16 AM
#1
Thread Starter
PowerPoster
Select LAST record in DB!??????
How the heck in a SQL statement can I select the LAST record in my DB?
thanks
-
Feb 5th, 2002, 11:23 AM
#2
Frenzied Member
There isn't a SQL command for getting the last record.
The only way would be to grab the entire collection and use .MOVELAST.
-
Feb 5th, 2002, 11:24 AM
#3
Code:
SELECT * FROM tablename WHERE key_column = (SELECT MAX(key_column) FROM tablename)
-
Feb 5th, 2002, 11:27 AM
#4
Frenzied Member
That will work, as long as you have got unique keys.
-
Feb 5th, 2002, 11:32 AM
#5
Frenzied Member
Actually that won't work
the MAX clause is quantitive, and not chronological, therefore you would only return the record with the highest value, and not necessarily the last record.
If you have a time stamped field you could use the MAX clause on this to achieve the desired effect.
-
Feb 5th, 2002, 11:37 AM
#6
go with the MOVELAST command. that will always work.
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Feb 5th, 2002, 11:39 AM
#7
This will work in SQL Server, Access and Sybase:
Code:
Select Top 1 * From MyTable Order By FieldId Desc
-
Feb 5th, 2002, 11:42 AM
#8
ahh good thinking serge.... TOP with a sort by Desc(ending) would work perfectly.
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Feb 5th, 2002, 11:46 AM
#9
-
Feb 5th, 2002, 11:49 AM
#10
Thread Starter
PowerPoster
Originally posted by Serge
This will work in SQL Server, Access and Sybase:
Code:
Select Top 1 * From MyTable Order By FieldId Desc
thank you all for your comments. They all work especially Serge's idea!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|