SQL order on float column not working

I have the following lines in my db:

ID Weight ----------------------------- 897 1.46357497509608E-11 689 6.67145488899268E-12 896 6.63573718293682E-12 615 5.14817058560092E-12 822 5.14806820534293E-12 

When I execute the following SQL query:

 SELECT * FROM mytable ORDER BY weight DESC 

data is returned in the same order.

PS the same thing comes from a Linq query in an ASP.NET C # application

+4
source share
1 answer

This order is correct.

In descending order, means that the highest values ​​come first. Your numbers are displayed in scientific notation . 1.46E-11 means 1.46 Γ— 10 -11 which is equal to 0.0000000000146.

Viewing numbers in the usual decimal form can help you understand why the order is correct:

  ID Weight
 897 0.00000000001463574975096080
 689 0.00000000000667145488899268
 896 0.00000000000663573718293682
 615 0.00000000000514817058560092
 822 0.00000000000514806820534293
+7
source

Source: https://habr.com/ru/post/1444390/


All Articles