Jump to content

Complex ORDER BY help


Canman2005

Recommended Posts

Hi all

 

I have the following database table

 

ID  VALUE

1    Apple

2    Microsoft

3    Mobiles

4    MP3s

5    Laptops

 

I use a "SELECT" query in my PHP to get those results.

 

Is it possible to "ORDER" my results by

 

ID number 2 first

 

ID number 1 second

 

and then the remainder of the results in a A-Z order

 

so the above would look like

 

ID  VALUE

2    Microsoft

1    Apple

5    Laptops

3    Mobiles

4    MP3s

 

I tried

 

ORDER BY  (CASE WHEN `id` = 2 THEN 0 WHEN `id` = 1 THEN 2 END), `value` ASC

 

But that doesn't seem to work no matter how much I tweak it around

 

Any help would be great

 

Thanks

 

Ed

Link to comment
https://forums.phpfreaks.com/topic/200481-complex-order-by-help/
Share on other sites

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.