SELECT * FROM `rsoft_module_fields` WHERE id in (3,7,1,5);
this is my query but the result show like id’s orderwise, but I need the order as What I given in in condition.
am expected result is given below
id 3 should be in 1 st row,
id 7 should be in 2 nd row,
id 1 should be in 3 rd row,
id 5 should be in 4 th row
and screenshot also attached for reference
>Solution :
SELECT t1.*
FROM `rsoft_module_fields` t1
JOIN (SELECT 3 id, 1 sorting_order UNION ALL
SELECT 7, 2 UNION ALL
SELECT 1, 3 UNION ALL
SELECT 5, 4) t2 USING (id)
ORDER BY t2.sorting_order
Alternatively:
SELECT *
FROM `rsoft_module_fields`
WHERE id in (3,7,1,5)
ORDER BY FIND_IN_SET(id, '3,7,1,5');