'MIN() function not returning the actual lowest number [duplicate]
So I have a table called FLIGHT which contains 3 columns. The first and second hold various IDs relating to airports, and the third contains the distance between them. When I try and query the table with the following:
SELECT * from flight
WHERE distance =
(SELECT min(distance) from flight);
It returns two IDS and a value of ~ 100. However, when I export the whole table and look at it in Excel, I can see that the shortest distance is actually 11. It seems like the query selected the lowest 3-digit number, because when I try the following:
SELECT * from flight
WHERE distance < 100;
It returns 20+ records.
Does anybody have any idea of what might be going on?
Solution 1:[1]
As it turns out my distance field was indeed a varchar. I had switched it from binary_double to try and troubleshoot an earlier problem and forgot to switch it back.
Thank you nicael and Ken for pointing me towards the datatype.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jacob |
