SELECT MIN() does not select negative value

Answered SELECT MIN() does not select negative value

  • Monday, April 30, 2012 9:15 PM
     
      Has Code

    Hey guys

    I want to select the most negative value from a column. The column temp that I use variates from -30 °C to +50°C.

    When I try this:

    SELECT MIN(temp) AS LowestTemp FROM tblMeasures

    I get 0 °C. This is "correct" because I have the value 0 °C in my column temp. However, I also have a lower value: -25,8 °C.

    It seems that the SELECT MIN() command ignores negative values.

    Does anyone know how to solve this?

    Thanks in advance.

    PS: I don't use SQL server, I only use access 2010. I need to get the value into my C# project. But that's no problem for me, it's just the SQL command that does not give what I desire


    • Edited by Gaius94 Monday, April 30, 2012 9:16 PM
    •  

All Replies

  • Monday, April 30, 2012 9:21 PM
    Moderator
     
      Has Code

    It works fine for me. What is the type of the temp column?

    declare @temperature table (temp decimal(10,2))
    insert into @temperature values (-30),(-12.2),(0),(10),(12.5), (31)
    
    select MIN(temp) as [Min Temp], max(temp) as [Max temp]
    from @temperature


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


  • Monday, April 30, 2012 9:26 PM
     
     

    A text type.

    I've also been thinking about this, it will probably have to be an int type, right?

    That would be a hard job to adjust that in my C# project since I create my tables there.

  • Monday, April 30, 2012 9:32 PM
    Moderator
     
     Answered
    It should be a decimal or numerical type (if you want to store temperature with decimal points). It should not be character (text). I actually guessed in may be a problem.

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    • Marked As Answer by Gaius94 Monday, April 30, 2012 10:03 PM
    •  
  • Monday, April 30, 2012 9:38 PM
     
     

    Ok i'll try to change the data type of my columns during the debugging of my program.

    I'll update this trade as soon as I managed to do so.

    Thanks a lot Naomi

    EDIT: I changed my column type to "number" and it works now. Thanks Naomi

    • Marked As Answer by Gaius94 Monday, April 30, 2012 10:02 PM
    • Edited by Gaius94 Monday, April 30, 2012 10:03 PM
    • Unmarked As Answer by Gaius94 Monday, April 30, 2012 10:03 PM
    •