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

后端 未结 5 810
天涯浪人
天涯浪人 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 22:58

    You could create a procedure to order the data in SQL, but that would be much more complicated than its native language counterpart.

    There's no "neat way" to resort the data like that in SQL -- the WHERE clause of a SELECT simply says "if these criteria are matched, include the row"; it's not (and it cannot be) an ordering criterion.

提交回复
热议问题