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.