Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

in(3,7,1,5) need this order wise result

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 referenceenter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading