[thelist] Custom sorting/ordering of query results [SOLVED!]

Matt Warden mwarden at gmail.com
Tue Aug 23 09:47:29 CDT 2005


On 8/23/05, Frank <lists at frankmarion.com> wrote:
> id       | name
> --------------------
> 1        | George
> 2        | Yuki
> 3        | Bob
> 4        | Fred
> 5        | Henry
> 6        | Rita
> The client wants all the women's name first. What to do? What to do? Do as
> such:
>    id
>  , name
> , FIND_IN_SET(name, '6,2,3,4,1,5') as sort_column
> FROM names
> ORDER BY sort_column;

Did you mean:
, FIND_IN_SET(id, '6,2,3,4,1,5') as sort_column

That's the only sense I can make of it.

And, yes, that's quite an elegant solution.

> Cool! Needless to say that we can also store lists as field type "set".,
> and thus retrieve the list of the DB.

I would personally just use varchar here, as it's atomic and more portable.

> Do you use MySQL? It's surprisingly rich with features. Read it's manual,
> specifically it's function reference. Lots of solutions to odd problems can
> be found there.

Just a warning that although extra features are great, breaking
portability might not be worth it (depending on your application).
Standard SQL itself is pretty rich with features, and many (most?)
things can be accomplished elegantly with it alone.

Nice tips, Frank.

Matt Warden
Miami University
Oxford, OH, USA

This email proudly and graciously contributes to entropy.

More information about the thelist mailing list