Click to See Complete Forum and Search --> : [RESOLVED] Order by alphabetical with other as last option


Phill Pafford
03-28-2007, 10:53 AM
Hi all,

Is there a way to order by alphabetical and then have the record other at the bottom of that?

Example Data Records:

pk | fields
----------------
1 | help
2 | fine
3 | hello
4 | world
5 | other
6 | foo
7 | bar
8 | good bye
9 | what


when doing the select statement can I get them to order like this?


pk | fields
----------------
7 | bar
2 | fine
6 | foo
8 | good bye
3 | hello
1 | help
9 | what
4 | world
5 | other


with it all being in alphabetical order except the other record which is listed last.

NightShift58
03-28-2007, 04:08 PM
SELECT *, IF(`fields`='other','zzzzzzzzzzzzzz',`fields`) as `sort_field`
FROM `myTABLE`
ORDER BY `sort_field` ASC

Phill Pafford
03-28-2007, 04:55 PM
thanks, works like a charm