Page 1 of 1

DESC and AC

Posted: Fri Mar 31, 2006 8:20 am
by Qaid
Hi,

When i use the function: ORDER BY id DESC

My post will be like this...
1, 2, 21, 22, etc, 3, ,31, 32, etc, 4, 5 ,6 ,7 ,8.....

Why that?

Thanks :)

Posted: Fri Mar 31, 2006 8:29 am
by Grim...
Looks like you have your ID in a TEXT field rather than an INT field.

Posted: Fri Mar 31, 2006 8:31 am
by Qaid
Looks like your right :D

Posted: Fri Mar 31, 2006 8:46 am
by onion2k
The fix..

Code: Select all

SELECT CAST(id AS UNSIGNED) AS reorderval FROM table ORDER BY reorderval DESC

Posted: Fri Mar 31, 2006 9:48 am
by feyd
Why not alter the table? If they're going to be numbers, there's no reason to keep them stored as textual data. The existing values will be converted to integers upon altering the table.

Posted: Fri Mar 31, 2006 9:50 am
by onion2k
feyd wrote:Why not alter the table?
Coz then I couldn't show off my knowledge of MySQL's magical functions.