SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Order by on multiple column?

    hey all,
    i got mysql query. i am using order by first_nameASC, but now i wan't another column with got values of pass or fail to to sorted too e.g pass comes on top and fail comes below it. can i apply order by on multiple column or is there any order way around?
    All those who wander aren't lost.

  2. #2
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Yes, you can do that:

    Code:
    SELECT name, score FROM results ORDER BY pass_or_fail DESC, first_name ASC;
    This is assuming pass_or_fail is a boolean field indicating 1 for a pass, 0 for a fail.

  3. #3
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    its datatype is double not bool
    All those who wander aren't lost.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by nofel View Post
    another column with got values of pass or fail
    Quote Originally Posted by nofel View Post
    its datatype is double not bool
    'pass' and 'fail' seem strings to me

    What value in your double column indicates 'pass', and what value indicates 'fail'?

  5. #5
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Actually i have two option (pass,fail was a dummy case), either its disqualified or amount of money. data type is double
    All those who wander aren't lost.

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by nofel View Post
    either its disqualified or amount of money.
    Disqualified? What value is that? NULL?

  7. #7
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    0
    All those who wander aren't lost.

  8. #8
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Ok, then Immerse's solution will work just fine.

    http://dev.mysql.com/doc/refman/5.5/en/select.html
    To sort in reverse order, add the DESC (descending) keyword to the name of the column in the ORDER BY clause that you are sorting by. The default is ascending order; this can be specified explicitly using the ASC keyword.

  9. #9
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It worked,
    All those who wander aren't lost.

  10. #10
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by nofel View Post
    i did, but its not working out.
    What does that mean? Is it not sorting the right way?
    is it possible that the query's 0 value is shown as Disqualified on fronted? or am i looking at some wrong column
    You lost me here. Is this something you would like, or is it something that is already happening?


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
  •