Reply to Re: Ordering results by order of the "IN' clause

Your name:

Reply:


Posted by Serge Rielau on 07/28/06 16:33

deane.barker@gmail.com wrote:
> Thanks.
>
> FYI -- I've learned in the meantime that MySQL has this functionality:
>
> ORDER BY FIELD(my_field, 'value2','value1','value3')
>
> Syntactic sugar, to be sure, but still handy.
The densest way to write it in ANSI SQL is this:
SELECT my_field FROM my_table JOIN (VALUES(1, 'value2'),
(2, 'value1'),
(3, 'value3')) AS V(I, val)
ON myfield = val
ORDER BY i

This way you don't need to repeat the values.

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ondemandbusiness/conf2006/

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация