Sort by order of values in a select statement “in” clause in mysql

后端 未结 4 855
挽巷
挽巷 2020-11-28 07:24

I\'m selecting a set of account records from a large table (millions of rows) with integer id values. As basic of a query as one gets, in a sense. What I\'m doing us build

4条回答
  •  有刺的猬
    2020-11-28 08:06

    Actually, this is better:

    SELECT * FROM your_table
    WHERE id IN (5,2,6,8,12,1)
    ORDER BY FIELD(id,5,2,6,8,12,1);
    

    heres the FIELD documentation:

    http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_field

提交回复
热议问题