Jump to content

Ordering rows by 2 columns


therealwesfoster

Recommended Posts

I have a question, how can I get information and show it in order according to 2 different columns in the db row?

 

Example:

MYTABLE:
id
name
number1
number2

 

I want to get all the rows from MYTABLE, and IF number1 is greater than 0, order them ASC. After all of the rows where number1 is greater than 0 are gone through, start with all the other rows and order them all ASC by number2.

 

I hope im making sense.. how could I do this with 1 query?

Link to comment
Share on other sites

I don't think you understood me completely.. thanks for the reply though.

 

I want to display all the rows. By default, number1 is left at 0. But if by chance if number1 is greater than 0, I want it to first grab all of those rows and order them by that number, then only AFTER all of the rows that contain a number greater than 0 in the number1 column are used, grab the rest of the rows and order them by their number (number2).

 

See, all of the rows have a number2, but by having something greater than 0 in the number1 column, I want them to get boosted up to the top of the list.

 

I think i explained it a little better this time :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.