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
https://forums.phpfreaks.com/topic/85074-ordering-rows-by-2-columns/
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 :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.