Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: Sort results by order in list

From: Sebastian Mendel <lists(at)sebastianmendel.de>
Date: Tue Oct 30 2007 - 05:38:57 EDT


Papalagi Pakeha schrieb:
> Hello,
>
> I have a query like:
> SELECT id, start_date FROM iddt WHERE id IN ('109k7','s3x6','sxmns','wt57');
> which gives me:
> +-------+---------------------+
> | id | start_date |
> +-------+---------------------+
> | 109k7 | 2007-10-07 12:06:58 |
> | sxmns | 2007-10-06 02:17:30 |
> | wt57 | 2007-10-07 15:57:37 |
> | s3x6 | 2007-10-07 08:58:20 |
> +-------+---------------------+
>
> How can I get the results sorted by the order in which they appear in
> the ID list?

i do not fully understand ... ORDER BY `id` ... ??? what ID List?

> Indeed I could do it in the application but prefer to get
> the results in the right order from MySQL as the ID list may be long
> and I may need only first few entries cropped by LIMIT clause. Ideally
> it should ORDER BY DATE(start_date) DESC and then by the ID list. Do I
> need some sort of stored function for that?

ORDER BY DATE(`start_date`) DESC, `id`

> I.e. the ideal output would be:
> +-------+---------------------+
> | id | start_date |
> +-------+---------------------+
> | 109k7 | 2007-10-07 12:06:58 |
> | s3x6 | 2007-10-07 08:58:20 |
> | wt57 | 2007-10-07 15:57:37 |
> | sxmns | 2007-10-06 02:17:30 |
> +-------+---------------------+

-- 
MySQL General Mailing List
For list archives: 
http://lists.mysql.com/mysql
To unsubscribe:    
http://lists.mysql.com/mysql?unsub=lists@pantek.com
Received on Tue Oct 30 05:37:02 2007

This archive was generated by hypermail 2.1.8 : Thu Jul 03 2008 - 08:43:19 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library