June 18, 2009

Sorting Multiple Columns With MySQL

Ever wanted to sort your MySQL results by several columns?

SELECT * FROM orderspecs ORDER BY height, depth, width;

Now what if you want the columns to have different sort orders in the sub-sorted columns? No problem. Just specify the order for each column.

SELECT * FROM orderspecs ORDER BY height DESC, depth ASC, width DESC;

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.