Jump to content

ORDER by DESC


Mutley

Recommended Posts

If you have numbers written in text or characters, and you want to sort them in Ascending order  and you don't want this:
mysql> select number from (table) order by number;

+--------+
| number |
+--------+
| 1      |
| 10    |
| 2      |
| 3      |
| 4      |
| 5      |
| 6      |
| 7      |
| 8      |
| 9      |
+--------+


Use this:
mysql> select number from (table) order by (number+0);

+--------+
| number |
+--------+
| 1      |
| 2      |
| 3      |
| 4      |
| 5      |
| 6      |
| 7      |
| 8      |
| 9      |
| 10    |
+--------+

The (field + 0 ) converts the text/character in the field into an integer.

Alternativley remap your table so that the column containing the numbers is type "integer"
Link to comment
https://forums.phpfreaks.com/topic/23345-order-by-desc/#findComment-105808
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.