[UPHPU] select 10 by date, order by name
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.
Author: Pro PHP-GTK
More information about the UPHPU