List:General Discussion« Previous MessageNext Message »
From:Brent Baisley Date:September 15 2006 3:25pm
Subject:Re: How to sort last n entries?
View as plain text  
This might work, I've used this syntax to select and sort from a UNION.

SELECT * FROM (SELECT * FROM table ORDER BY id DESC LIMIT n) AS ltable ORDER BY datefield
DESC

According to the documentation you can use limit in subqueries:

A subquery can contain any of the keywords or clauses that an ordinary SELECT can contain:
DISTINCT, GROUP BY, ORDER BY, LIMIT,...


----- Original Message ----- 
From: "Dominik Klein" <dk@stripped>
To: <mysql@stripped>
Sent: Friday, September 15, 2006 5:44 AM
Subject: Re: How to sort last n entries?


> Peter Lauri schrieb:
>> SELECT * FROM table WHERE id=(SELECT id FROM table ORDER BY id DESC) ORDER
>> BY date
> 
> This does not limit it to n entries (order by date limit n is not 
> sufficient as I need last (highest) n ids). And afaik, limit is not 
> allowed in sub-queries.
> 
> -- 
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/mysql?unsub=1
>
Thread
How to sort last n entries?Dominik Klein15 Sep
  • Re: How to sort last n entries?Chris Sansom15 Sep
    • Re: How to sort last n entries?Dominik Klein15 Sep
  • Re: How to sort last n entries?Martijn Tonies15 Sep
  • RE: How to sort last n entries?Peter Lauri15 Sep
RE: How to sort last n entries?Peter Lauri15 Sep
Re: How to sort last n entries?Dominik Klein15 Sep
  • RE: How to sort last n entries?Peter Lauri15 Sep
  • RE: How to sort last n entries?Peter Lauri15 Sep
Re: How to sort last n entries?Brent Baisley15 Sep