mysql query order by multiple items

Alexander picture Alexander · Feb 2, 2011 · Viewed 151.7k times · Source

is is possible to order by multiple rows?

I want my users to be sorted by last_activity, but at the same time, i want the users with pictures to appear before the ones without

Something like this:

SELECT some_cols
FROM `prefix_users`
WHERE (some conditions)
ORDER BY last_activity, pic_set DESC;

Answer

ihorko picture ihorko · Feb 2, 2011
SELECT some_cols
FROM prefix_users
WHERE (some conditions)
ORDER BY pic_set DESC, last_activity;