From: Martijn Tonies Date: September 15 2006 9:13am Subject: Re: How to sort last n entries? List-Archive: http://lists.mysql.com/mysql/201878 Message-Id: <00eb01c6d8a7$27efe8d0$cd02a8c0@martijnws> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit > > At 10:41 +0200 15/9/06, Dominik Klein wrote: > >> I have a table with primary key "id". Another field is "date". Now I > >> want the last n entries, sorted by "date". > >> > >> Is this possible in one SQL statement? > > > > ORDER BY `date` DESC LIMIT n > > > > Last n entries means I want the last (highest) n ids. And that result > sorted by date. ORDER BY `id` DESC, `date` ASC LIMIT n I think :-) Martijn Tonies Database Workbench - development tool for MySQL, and more! Upscene Productions http://www.upscene.com My thoughts: http://blog.upscene.com/martijn/ Database development questions? Check the forum! http://www.databasedevelopmentforum.com