List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:July 15 1999 5:23pm
Subject:Re: Sorting question
View as plain text  
At 7:01 PM +0300 7/15/99, <sinisa@stripped> wrote:
>E.L. writes:
> > Hi all
> >
> > Is it possible to sort in different way that ascending
> > and descending with ORDER BY
> >
> >
> > ++++++++++++++++
> > classified        region
> > ++++++++++++++++
> > ford                    zc
> > dodge                pb
> > dodge                zc
> > nissan                ac
> > ford                     ac
> >
> > I would like to make my own rules of ORDER BY
> >
> > Like
> >
> > select * from cars ORDER BY region (zc, ac, pb ...)
> >
> > I have no clue of doing it.
> >
> > Can somebody help me on this ...
> >
> > Newbie
> >
> > Thank you
> >
> >
>
>Hi!
>
>Consider making region an ENUM type.
>
>
>Sinisa

Way to go, Sinisa.  While my answer (no, you can only sort on ascending
and descending) is technically correct, I'm afraid it wasn't very helpful.
Sinisa's is a much better answer.

I was thinking about this some more, and there is another way to do
this that doesn't require the field to be an ENUM, and lets you specify
your sort order.

You can map column values onto integers using the FIELD() function, then
sort on those integers.  For example, you might be able to do this:

SELECT *,FIELD(region,'zc','ac','pb',...) AS f FROM cars ORDER BY f

--
Paul DuBois, paul@stripped
Thread
Sorting questionE.L.15 Jul
  • Re: Sorting questionPaul DuBois15 Jul
  • Sorting questionsinisa15 Jul
    • Re: Sorting questionPaul DuBois15 Jul
      • Re: Sorting questionsinisa16 Jul
Re: Sorting questionKevin Smith15 Jul