Jump to content

Archived

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

Tandem

Mysql ordering

Recommended Posts

If i want to order some query results by a factor that has no sort of reasonable order, but i know which order they should be in e.g

1. Dog
2. Cat
3. Lion

or something like that, how would i go about doing that?

If you need more information or i don't make sense, please ask/say.

Thanks in advance for any help.

Share this post


Link to post
Share on other sites
You could use a SQL CASE statement
[code]
SELECT animal FROM mytable
ORDER BY
CASE
    WHEN animal='Dog' THEN 1
    WHEN animal='Cat' THEN 2
    WHEN animal='Lion' THEN 3
    ELSE 99
END
[/code]

Share this post


Link to post
Share on other sites

×

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.