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 13:45:23 -0400
- From: "Jerry Schwartz" <jschwartz@xxxxxxxxxxxxxxxx>
- Subject: ***BOGO*** RE: force row to appear at top of results using order by
>-----Original Message-----
>From: Andrew Martin [mailto:sublimino@xxxxxxxxx]
>Sent: Tuesday, July 01, 2008 9:20 AM
>To: mysql@xxxxxxxxxxxxxxx
>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?
>
[JS] IMHO, you are better off approaching this in a different way. Add a
third column that is used only as a sort key, so that you can rearrange your
sort order whenever you want. I would use a sort key that has two decimal
places, so that you can easily add an entry that needs to be sorted between
1.00 and 2.00 just by giving it a sort key of 1.50. This will give you
complete flexibility, and should use minimal overhead.
>Many thanks,
>
>
>Andy
>
>--
>MySQL General Mailing List
>For list archives: http://lists.mysql.com/mysql
>To unsubscribe: http://lists.mysql.com/mysql?unsub=jschwartz@the-
>infoshop.com
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=royale@xxxxxxxxxx