1

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?

Jacob
  • 11
  • 2
  • 2
    What data type is your `distance` column? – Ken White Apr 06 '22 at 23:44
  • 1
    Possible duplicate: [SQL SERVER - Understanding how MIN(text) works](https://stackoverflow.com/questions/4503703/sql-server-understanding-how-mintext-works) (I believe your field is something like varchar) – nicael Apr 06 '22 at 23:46

1 Answers1

0

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.

Jacob
  • 11
  • 2