Closed Thread
Results 1 to 8 of 8

Thread: MySQL ORDER BY

  1. #1
    Sup, Recoil here. themoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond repute themoose's Avatar
    Join Date
    Jun 2005
    Location
    Uzbekistan
    Posts
    8,805

    MySQL ORDER BY

    Does anybody know if it's possible to ORDER BY something conditionally

    Basically, I want to order by `ranking` ASC where `ranking` isn't '0' , and then display the '0' ones afterwards.

    I know it's easily done with more than one query but I'm interested to know if it's possible with just one query.

    Currently it's:

    0
    0
    0
    0
    1
    5
    38
    192

    And I want:

    1
    5
    38
    192
    0
    0
    0
    0

  2. #2
    Senior Member hip_hop_x has a little shameless behaviour in the past
    Join Date
    Sep 2006
    Posts
    223
    ORDER BY ranking DESC WHERE ranking > 0
    Coderi Leader
    http://www.coderi.ro

  3. #3
    Sup, Recoil here. themoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond repute themoose's Avatar
    Join Date
    Jun 2005
    Location
    Uzbekistan
    Posts
    8,805
    Nope.. doesn't work (and I already tried it before).

  4. #4
    Senior Member hip_hop_x has a little shameless behaviour in the past
    Join Date
    Sep 2006
    Posts
    223
    how the type of ranking ?
    Coderi Leader
    http://www.coderi.ro

  5. #5
    Sup, Recoil here. themoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond repute themoose's Avatar
    Join Date
    Jun 2005
    Location
    Uzbekistan
    Posts
    8,805
    I'm not sure what you mean.. the column type is TINYINT, though.

  6. #6
    Senior Member hip_hop_x has a little shameless behaviour in the past
    Join Date
    Sep 2006
    Posts
    223
    sorry i didn't gave you a good answer, also my question is written badly. I can make it display this:
    1
    5
    28
    192
    Without 0, it will be like this
    Code:
    SELECT * FROM `table` WHERE rank > 0 ORDER BY rank ASC
    Coderi Leader
    http://www.coderi.ro

  7. #7
    Sup, Recoil here. themoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond reputethemoose has a reputation beyond repute themoose's Avatar
    Join Date
    Jun 2005
    Location
    Uzbekistan
    Posts
    8,805
    I want the 0, but I want them to be ordered after the other numbers.

    It's probably not possible with 1 query (I know definitely it is with 2) - but that's what I'm after.

  8. #8
    oarcadescript.com JohnN is a glorious beacon of lightJohnN is a glorious beacon of lightJohnN is a glorious beacon of lightJohnN is a glorious beacon of lightJohnN is a glorious beacon of lightJohnN is a glorious beacon of light JohnN's Avatar
    Join Date
    Feb 2007
    Posts
    1,023
    use COUNT(*) to get the total number of rows, then use numrows to get rows that are NOT 0, then subtract numrows from COUNT(*) and you have the number of entries that are 0.

Closed Thread

Similar Threads

  1. order a-z in php
    By needlehost in forum Programming Help
    Replies: 1
    Last Post: April 4th, 2006, 11:34
  2. php order
    By needlehost in forum Programming Help
    Replies: 5
    Last Post: April 1st, 2006, 02:05
  3. mySQL - ORDER BY
    By nickmahon in forum Programming Help
    Replies: 0
    Last Post: September 15th, 2002, 15:53
  4. Order By
    By agent007 in forum Programming Help
    Replies: 1
    Last Post: August 10th, 2002, 12:00
  5. Using php to order...
    By Mekhu in forum Programming Help
    Replies: 0
    Last Post: December 14th, 2001, 17:25

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