Helping ordinary people create extraordinary websites!
   

How to do mysql query and have it ordered by two fields?

Friday, 9th October 2009
by VistaXP


I would like to sort my query results by two fields say with the first column having priority over the second one.



phpdreams
SELECT * FROM my_table ORDER BY lastname, firstname ASC

That will sort by both fields in ASCending order. You can also specify a direction for each order field as such:

SELECT * FROM my_table ORDER BY lastname DESC, firstname ASC


:o)
Friday, 9th October 2009
Votes:
31
15

More MySQL Help:
» How to publish a newsletter using PHP and MySQL?
» How to get first letter of a field in MySQL?
» How to make a simple image database ?
» Backup MySQL Database
» How to do nested select statements with MySQL?

SPREAD THE WORD!
Tell a Friend

GET OUR NEWS


Developer Resources