par
Hubert Roksor » 23 févr. 2006, 02:30
FIND_IN_SET() devrait correspondre à tes besoins, sinon tu peux essayer FIELD() (juste au dessus).
Code : Tout sélectionner
SELECT information
FROM table
WHERE id IN(8,2,7,5,1)
ORDER BY FIND_IN_SET(id, '8,2,7,5,1')
Code : Tout sélectionner
SELECT information
FROM table
WHERE id IN(8,2,7,5,1)
ORDER BY FIELD(id, 8, 2, 7, 5, 1)
Attention toutefois, ce genre de solution "atypique" est souvent le symptôme d'un algorithme qui aurait besoin d'être repensé.
[url=http://dev.mysql.com/doc/refman/5.0/fr/string-functions.html#id3080207]FIND_IN_SET[/url]() devrait correspondre à tes besoins, sinon tu peux essayer FIELD() (juste au dessus).
[code]SELECT information
FROM table
WHERE id IN(8,2,7,5,1)
ORDER BY FIND_IN_SET(id, '8,2,7,5,1')[/code]
[code]SELECT information
FROM table
WHERE id IN(8,2,7,5,1)
ORDER BY FIELD(id, 8, 2, 7, 5, 1)[/code]
Attention toutefois, ce genre de solution "atypique" est souvent le symptôme d'un algorithme qui aurait besoin d'être repensé.