vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| Chris Sansom schrieb: > 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. |
| |||
| 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 -- Cheers... Chris Highway 57 Web Development -- http://highway57.co.uk/ A censor is a man who knows more than he thinks you ought to. -- Laurence J. Peter |
| |||
| SELECT * FROM table WHERE id=(SELECT id FROM table ORDER BY id DESC) ORDER BY date -----Original Message----- From: Dominik Klein [mailto:dk@in-telegence.net] Sent: Friday, September 15, 2006 3:41 PM To: mysql@lists.mysql.com Subject: How to sort last n entries? 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? Thanks for your help Dominik -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=lists@dwsasia.com |
| |||
| > > 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 |
| ||||
| 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? > > Thanks for your help > Dominik Hmmm, maybe SELECT * FROM table ORDER BY `date` ASC, `id` DESC LIMIT 10 -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |