开发者

Search result in presented in specific order?

SELECT id FROM films WHERE id IN (90,4,40)

result

4
40
90

but I want it return 90,4,40 what I must do? (mysql)


SORRY , but one more question :

SELECT id FROM films WHERE id IN (90,4,40) ORDER BY FIELD(id, 90, 4, 40) is ok but truthfully

 for ( $i = 1; $i <10; $id ++ 开发者_StackOverflow中文版){
     $IDarray[] = random();
 }


SELECT id FROM films WHERE id IN "(". implode(',',$IDarray). " ) ";

I want order by ID as above but ID is random, i want keep order random of ID


ORDER BY CASE `id` WHEN 90 THEN 0
                   WHEN 4 THEN 1
                   WHEN 40 THEN 2
                   ELSE 3
         END CASE

OR

ORDER BY FIND_IN_SET(`id`, '90,4,40')

OR

ORDER BY FIELD(`id`, 90, 4, 40)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜