Keep order from 'IN' clause

后端 未结 5 1420
花落未央
花落未央 2020-12-11 00:23

Is it possible to keep order from a \'IN\' conditional clause?

I found this question on SO but in his example the OP have already a sorted \'IN\' clause.

My

5条回答
  •  -上瘾入骨i
    2020-12-11 01:00

    Try this:

    SELECT T.SomeField,T.OtherField
    FROM TestResult T
     JOIN 
       (
         SELECT 1 as Id, 45 as Val FROM dual UNION ALL
         SELECT 2, 2 FROM dual UNION ALL
         SELECT 3, 445 FROM dual UNION ALL
         SELECT 4, 12 FROM dual UNION ALL
         SELECT 5, 789  FROM dual
       ) I
       ON T.SomeField = I.Val
    ORDER BY I.Id
    

提交回复
热议问题