[UPHPU] select 10 by date, order by name
Scott Mattocks
scott at crisscott.com
Tue Feb 26 12:57:38 MST 2008
Wade Preston Shearer wrote:
>> select * from table t order by t.date desc, t.name desc limit 10
>
> Wow. I didn't know you could order by multiple columns. Thank you.
That doesn't do what you want though. That returns the first 10 rows
sorted by date, and if two have the same date, sorts those by name.
There is no good way to do what you want in SQL. It will require at
least one subselect and if the table has a significant amount of rows it
will be painfully slow.
You are better off sorting by date, limiting by 10 and then sorting the
result in PHP by name.
--
Scott Mattocks
Author: Pro PHP-GTK
http://www.crisscott.com
More information about the UPHPU
mailing list