lists.zerezo.com
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
***BOGO*** Re: force row to appear at top of results using order by
- Date: Tue, 1 Jul 2008 15:40:34 +0100
- From: "Andrew Martin" <sublimino@xxxxxxxxx>
- Subject: ***BOGO*** Re: force row to appear at top of results using order by
Many thanks for the quick replies! This solution appears the most elegant:
---------- Forwarded message ----------
From: Markus Grossrieder <markus.grossrieder@xxxxxxxx>
Date: 2008/7/1
Subject: Re: force row to appear at top of results using order by
To: Andrew Martin <sublimino@xxxxxxxxx>
Andrew,
something like this (air code)
SELECT events_groups_id, events_groups_name,
IF(events_groups_name='Personal Events', 1, 2) as sort_elem
FROM events_groups;
ORDER BY sort_elem, events_groups_name;
Regards,
Markus
----- Original Message ----- From: "Andrew Martin" <sublimino@xxxxxxxxx>
To: <mysql@xxxxxxxxxxxxxxx>
Sent: Tuesday, July 01, 2008 3:19 PM
Subject: force row to appear at top of results using order by
> Hello,
>
> I have an order by question...
>
> This is the "raw" data...
>
> mysql> SELECT events_groups_id, events_groups_name FROM events_groups;
> +------------------+---------------------+
> | events_groups_id | events_groups_name |
> +------------------+---------------------+
> | 1 | Personal Events |
> | 2 | Company events |
> | 3 | Deliveries in |
> | 4 | Invoices to pay |
> | 5 | Invoices to receive |
> | 6 | Deliveries out |
> | 9 | Online demos |
> +------------------+---------------------+
> 7 rows in set (0.01 sec)
>
>
> This is almost the result I require:
>
> mysql> SELECT events_groups_id, events_groups_name FROM events_groups
> ORDER BY events_groups_name ASC;
> +------------------+---------------------+
> | events_groups_id | events_groups_name |
> +------------------+---------------------+
> | 2 | Company events |
> | 3 | Deliveries in |
> | 6 | Deliveries out |
> | 4 | Invoices to pay |
> | 5 | Invoices to receive |
> | 9 | Online demos |
> | 1 | Personal Events |
> +------------------+---------------------+
> 7 rows in set (0.00 sec)
>
>
> I would like this to have Personal Events appear first, and the rest
> of the list still be alphabetically sorted like so:
>
> +------------------+---------------------+
> | events_groups_id | events_groups_name |
> +------------------+---------------------+
> | 1 | Personal Events |
> | 2 | Company events |
> | 3 | Deliveries in |
> | 6 | Deliveries out |
> | 4 | Invoices to pay |
> | 5 | Invoices to receive |
> | 9 | Online demos |
> +------------------+---------------------+
>
> Is this possible without using a subquery or union?
>
> Many thanks,
>
>
> Andy
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=markus.grossrieder@xxxxxxxx
>
--------------------------------------------------------------------------------
No virus found in this incoming message.
Checked by AVG.
Version: 8.0.101 / Virus Database: 270.4.3/1528 - Release Date: 7/1/2008 7:26 AM
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=royale@xxxxxxxxxx