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

前端 未结 6 766
孤街浪徒
孤街浪徒 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:44

    Try selecting the data using 3 UNION ALL queries:

    SELECT * FROM Members WHERE MemberID = "6"
    UNION ALL
    SELECT * FROM Members WHERE MemberId = "3"
    UNION ALL
    SELECT * FROM Members WHERE MemberID = "5"
    

    or maybe you need to simply add a new column to hold the sort order ?

提交回复
热议问题