Select query using IN() and without any sorting

前端 未结 2 724
我在风中等你
我在风中等你 2020-12-29 12:34

My query

select * from product where productId in(25,36,40,1,50);

Result shows as follows

`productId   ProductName  Qty Pr         


        
相关标签:
2条回答
  • 2020-12-29 13:19

    If you want them to be randomly ordered, do:

    select * from product where productId in(25,36,40,1,50) ORDER BY RAND()
    

    The default ordering is probably due to the way the IDs are sorted in the index.

    0 讨论(0)
  • 2020-12-29 13:39
    select * 
    from product 
    where productId in(25,36,40,1,50) 
    order by find_in_set(productId, '25,36,40,1,50');
    

    See this SQLFiddle

    0 讨论(0)
提交回复
热议问题