Re: Selecting and sorting the last 5 entries.
Dimiter Ivanov wrote:
> "SELECT * FROM songs WHERE 1 ORDER BY ID DESC
> LIMIT 5"
>
> But what if i want to sort those last 5 entries by song title ?
> I was able to do that with subqueries, but on my current server i have older version of mysql that
> does not support subqueries.
>
> Any ideas ?
The following kludge seems to work (using a UNION):
(SELECT * FROM songs ORDER BY ID DESC LIMIT 5)
UNION
(SELECT * FROM songs ORDER BY ID DESC LIMIT 5)
ORDER BY TITLE LIMIT 5;
Depending on how well you know your data, you could even replace one of the SELECTs in your UNION with
(SELECT 0, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz')
--
felix
Please use
BBCode to format your messages in this forum.