SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2007
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    CONVERT() not converting properly

    I have a table example:

    Code:
    id  -- score
    1   -- 5.66678
    2   -- 11.598
    3 -- 12.2
    4 -- 11.598
    5 -- 2.577777
    score is set as a VARCHAR currently.
    id is an integer

    My simple MySQL query:

    Code:
    SELECT *
    FROM `mysql_table`
    ORDER BY CONVERT( score, DECIMAL ) DESC
    For some reason it pulls it something similar to this:

    Code:
    id  -- score
    2   -- 11.598
    3 -- 12.2
    4 -- 11.598
    1   -- 5.66678
    5 -- 2.577777
    12.2 is stuck between the two 11.598's. Is there a reason for this? Am I doing something wrong?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,021
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    please run this and show what it produces...
    Code:
    SELECT *
         , CONVERT( score, DECIMAL ) AS sortby
      FROM `mysql_table`
    ORDER 
        BY CONVERT( score, DECIMAL ) DESC
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •