Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Other Web Development Languages (http://www.programmingforums.org/forum40.html)
-   -   mysql get last 10 records in a table (http://www.programmingforums.org/showthread.php?t=13439)

kruptof Jun 28th, 2007 2:47 PM

mysql get last 10 records in a table
 
Does anybody know whether it is possible to get the last 10 records in a table, without having to load the whole contents of the table? If that's not possible then what other way would you recommend.

Infinite Recursion Jun 28th, 2007 3:01 PM

If it has some sort of sequential id or date associated with the record, you could do this:

SELECT * FROM mytable ORDER BY seq_id DESC LIMIT 10;

Basically, this puts the last entries on top (via sorting in descending order), then limiting the results to 10 via LIMIT.

kruptof Jun 28th, 2007 4:29 PM

Thanks a bunch IR that was exactly what I was looking for.

Infinite Recursion Jun 29th, 2007 9:23 AM

Glad you got it worked out man.


All times are GMT -5. The time now is 12:19 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC