| Welcome to WebmasterWorld Guest from 18.104.22.168 |
register, login, search, subscribe, help, library, PubCon, announcements, recent posts, open posts,
|Pubcon Platinum Sponsor|
|Order Numbers in MySQL Table Largest First|
Order By seems to only sort with smallest first
| 6:10 pm on Jan 14, 2007 (gmt 0)|
I have a MySQL table with several columns, including one that contains numbers.
I can order this table and select the five lowest numbers using this command:
mysql_query("SELECT * FROM table ORDER BY number LIMIT 5");
However, say I want the five largest numbers, how do I do that?
In various searches I couldn't find anything about ordering numbers the opposite way, and in my various attempts I even tried with no avail:
mysql_query("SELECT * FROM table ORDER BY MAX(number) LIMIT 5");
Is there a way to do this?
| 6:34 pm on Jan 14, 2007 (gmt 0)|
"DESC" will reverse the sort order:
SELECT * FROM table ORDER BY number LIMIT 5 DESC
| 6:37 pm on Jan 14, 2007 (gmt 0)|
Figured this one out:
mysql_query("SELECT * FROM table ORDER BY number DESC LIMIT 5");
I just needed to add DESC after what I wanted to by ordered.
| 4:23 am on Jan 15, 2007 (gmt 0)|
Sorry zCat, thanks for the reply.
I didn't realize you had already replied when I typed my second message.
Glad we came up with the same answer!
| 9:25 am on Jan 15, 2007 (gmt 0)|
No problem :-) (though I notice I put the "DESC" in the wrong position).
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld ® and PubCon ® are a Registered Trademarks of Pubcon Inc.
© Pubcon Inc. 1996-2012 all rights reserved