Returning query results in predefined order

前端 未结 11 1033
温柔的废话
温柔的废话 2020-11-29 06:01

Is it possible to do a SELECT statement with a predetermined order, ie. selecting IDs 7,2,5,9 and 8 and returning them in that order, based on

11条回答
  •  悲哀的现实
    2020-11-29 06:35

    Erm, not really. Closest you can get is probably:

    SELECT * FROM table WHERE id IN (3, 2, 1, 4) ORDER BY id=4, id=1, id=2, id=3
    

    But you probably don't want that :)

    It's hard to give you any more specific advice without more information about what's in the tables.

提交回复
热议问题