How do I preserve the order of a SQL query using the IN command

后端 未结 5 831
天涯浪人
天涯浪人 2020-12-20 22:47
SELECT * FROM tblItems
WHERE itemId IN (9,1,4)

Returns in the order that SQL finds them in (which happens to be 1, 4, 9) however, I want them retur

5条回答
  •  悲&欢浪女
    2020-12-20 23:09

    I had the same task once in a mysql environment.

    I ended up using

    ORDER BY FIND_IN_SET(itemID, '9,1,4')

    this is working for me since then. I hope it also works for sqlite

提交回复
热议问题