Ordering by the order of values in a SQL IN() clause

前端 未结 13 963
旧巷少年郎
旧巷少年郎 2020-11-22 04:12

I am wondering if there is away (possibly a better way) to order by the order of the values in an IN() clause.

The problem is that I have 2 queries, one that gets al

13条回答
  •  孤城傲影
    2020-11-22 04:41

    Two solutions that spring to mind:

    1. order by case id when 123 then 1 when 456 then 2 else null end asc

    2. order by instr(','||id||',',',123,456,') asc

    (instr() is from Oracle; maybe you have locate() or charindex() or something like that)

提交回复
热议问题