Jump to content

[SOLVED] Need help with ORDER BY and ASC command


ERuiz

Recommended Posts

I am running the following query:

SELECT * FROM pirep ORDER BY LandingVS ASC LIMIT 20

The problem is that the field LandingVS contains numbers such as these:

-231.45
-191.92
-234.22
-47.22
-82.11

The PROPER output should be:

-47.22
-82.11
-191.92
-231.45
-234.22

The query above, is outputting this:

-191.92
-231.45
-234.22
-47.22
-82.11


As you can see, it is reading each number from left to right, when deciding to do the order by. I need it to start from right to left, so that the true ASC can take place.

Thanks for any help...

ERuiz
If your datatype is float, it will sort properly. You probably have it set to varchar.

I created a new table and inserted the values you gave and then ran the query

[code]SELECT *
FROM `test`
ORDER BY DATA ASC[/code]

It returned

[code]
-234.22
-231.45
-191.92
-82.11
-47.22[/code]

Data types really do matter. They tell MySql how to handle the data. Varchar sorts by the first letter/ number.... float tells it that the data is a floating point integer thereby sorting properly

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.