MySQL Forums
Forum List  »  Newbie

Re: Two types of sorting into one request
Posted by: Felix Geerinckx
Date: June 27, 2005 02:17AM

Jay Pipes wrote:

> Use a UNION with ORDER BY NULL on outermost result
> to prevent MySQL from sorting:
>
> (
> SELECT *
> FROM YourTable
> WHERE date > DATE_SUB(CURRENT_DATE(), INTERVAL
> 30 DAY)
> ORDER BY weith
> )
> UNION ALL
> (
> SELECT *
> FROM YourTable
> WHERE date <= DATE_SUB(CURRENT_DATE(), INTERVAL
> 30 DAY)
> ORDER BY date, weith
> ) ORDER BY NULL;

This will not work: the ORDER BY's in the subselects are optimized away.

From http://dev.mysql.com/doc/mysql/en/union.html:

"ORDER BY for individual SELECT statements within parentheses only has an effect when combined with LIMIT. Otherwise, the ORDER BY is optimized away."

--
felix
Please use BBCode to format your messages in this forum.

Options: ReplyQuote


Subject
Written By
Posted
Re: Two types of sorting into one request
June 27, 2005 02:17AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.