List:General Discussion« Previous MessageNext Message »
From:Steve Edberg Date:September 21 2001 12:31pm
Subject:Re: Advanced ORDER BY
View as plain text  
You _might_ also be able to do something like:

    SELECT *
    FROM news
    WHERE newstype='1' AND global='1'
    ORDER BY concat(if(depart='center', 'A', 'B'), SortNumber) ASC

I don't have quite enough info here, but I'm going to assume that you 
want the records with depart='center' sorted first AND in alphabetic 
order, then the rest of the records in alphabetic order. I'm also 
going to assume that 'SortNumber' is actually the CHAR field you want 
the alphabetic sort on; if it isn't, replace it with the name of the 
field you want to sort by.

The intent here is to prefix the original sort order (SortNumber) 
with an 'A' for depart='center' records, so they sort before the 
other records (prefixed with a 'B').


At 4:01 PM +0400 9/21/01, Ilya Martynov <m_ilya@stripped> wrote:
>l> Hello,
>l> I'm trying to do a mysql select statement like this:
>l> SELECT * FROM news WHERE newstype = '1' AND global = '1' OR depart =
>l> 'center' ORDER BY SortNumber ASC
>l> But I would like the ORDER BY to list all records where depart = 'center'
>l> first and then all the rest of the depart records in
>l> alphabetical order.
>l> Any ideas?
>Use two queries: one to get records where depart = 'center' and second
>for rest of the depart records.
>  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>| Ilya Martynov (                                    |
>| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
>| AGAVA Software Company (                          |
>  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

+------------------------ Open source questions? ------------------------+
| Steve Edberg                           University of California, Davis |
| sbedberg@stripped                               Computer Consultant |
|         |
+----------- -----------+
Advanced ORDER BYlarentium21 Sep
  • Re: Advanced ORDER BYIlya Martynov21 Sep
    • Re: Advanced ORDER BYSteve Edberg21 Sep
  • Re: Advanced ORDER BYHarald Fuchs21 Sep