MySQL MAX function always returns 99

Discussion in 'MySQL' started by thuankkk, Apr 13, 2009.

  1. #1
    Hi,

    Yesterday I encounter a silly problem: I wanna get the max value of UserID, and try the MAX function, like this
    SELECT MAX(userid) AS max FROM usertable;
    Code (markup):
    But the MAX function always returns 99, not the highest value (about 200+).
    Tried google, and I found nothing :(

    After that, I think there's some error with the data type, as the MAX is used for number only.

    Then, I changed the data type from VARCHAR to INT, and all works :)

    So, I made a post and hope this will help someone :)
     
    thuankkk, Apr 13, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Is there a problem with using an INT field vs. a VARCHAR? The max or any other comparison function will not work properly on a non numerical field.
     
    jestep, Apr 13, 2009 IP
  3. harpreetjuit

    harpreetjuit Peon

    Messages:
    200
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Great never tried this indeed
    :)
    thanks
     
    harpreetjuit, Apr 13, 2009 IP