Order results to match the order of values in a WHERE IN expression

前端 未结 6 754
孤街浪徒
孤街浪徒 2021-02-13 03:06

Is there a way I can make mysql return results from a Member database by the order I ask it by in the WHERE command?

SELECT * 
FROM Members 
WHERE MemberID = \"6         


        
6条回答
  •  野性不改
    2021-02-13 03:28

    Try this:

    SELECT * FROM Members
    ORDER BY CASE MemberId
        WHEN 6 THEN 1
        WHEN 3 THEN 2
        WHEN 5 THEN 3
        ELSE 999
    END
    

提交回复
热议问题