Click to See Complete Forum and Search --> : Ordering by a number column


damon2003
11-12-2003, 04:58 AM
Hi,
I am querying a database and and returning the results ordered by a column that contains codes(numbers).
However, the results are not being ordered as I want. I get something like this:

1
10
11
2
3

Its only ordering on the first digit. Does anyone know how to resolve this?
thanks

Khalid Ali
11-12-2003, 07:01 AM
you may want to use ASCENDING aor DESCENDING commands as well in addition to the ORDER BY
.you will have to look up the corrrect syntax in MySQL for ASCENDING or DESCENDING

pyro
11-12-2003, 08:19 AM
#ascending
"SELECT `fieldname` FROM `tablename` ORDER BY `id`"; #default is ASC
#descending
"SELECT `fieldname` FROM `tablename` ORDER BY `id` DESC";;)

damon2003
11-12-2003, 11:33 AM
I actually had ASC in the original and its still ordering only on the first digit of the number.
I just thought maybe its how the database is set up, could it be that the column is a text column, I dont configure the database

pyro
11-12-2003, 11:51 AM
Yes, if it is a text column it will not work correctly. You want to make sure that you are using a numeric type for the field (I think varchar will also work).