PHP Order By Multiple Fields in MySQL

Want to be able to order by two or more database fields / columns using the ASC and DESC order clause

You can sort query results in ascending or descending order on one or more of the columns in the result set by using the ASC or DESC keywords with the ORDER BY clause.

Ordering By Two Fields

SELECT * FROM table ORDER BY (field1 / field2) DESC

Ordering By Three Fields

If both field1 and field2 match in more then one row, then use a third to order them by:

SELECT * FROM table ORDER BY (field1 / field2) DESC, field3 DESC

Tagged : / / / / / /

10 thoughts on “PHP Order By Multiple Fields in MySQL

Leave a Reply

Your email address will not be published. Required fields are marked *