MySQL ORDER BY messed up?

Discussion in 'MySQL' started by bobby9101, May 29, 2007.

  1. #1
    I am pulling the following results from MySQL
    655617600
    1180454612
    1180454516
    1180454322

    And that is how they ordered it when I did:
    ORDER BY date DESC

    Clearly "655617600" is smaller than "1180454322"
    How do I rectify this?
     
    bobby9101, May 29, 2007 IP
  2. Clark Kent

    Clark Kent Guest

    Messages:
    122
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    what is your field type?
     
    Clark Kent, May 29, 2007 IP
    bobby9101 likes this.
  3. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #3
    it was varchar, now it is int and it works correctly
    thanks a bunch
     
    bobby9101, May 29, 2007 IP
  4. Clark Kent

    Clark Kent Guest

    Messages:
    122
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    FYI: If you need that sorting on varchar fields, cast it to unsigned.
    Example:
    select cast("123" as unsigned)
    or
    select yourfieldname from yourtable order by cast(yourfieldname as unsigned)
     
    Clark Kent, May 29, 2007 IP