rusly
rusly

Reputation: 1524

ORDER BY id based on id inside IN

How to ORDER BY id based on id inside IN

SELECT * 
FROM mall 
WHERE mall_id IN (3331083,33310110,3331080,33310107,33310119,3331410) 
      AND mall_status='1' LIMIT 50 

the result should be :

  1. 3331083
  2. 33310110
  3. 3331080 ....

Upvotes: 3

Views: 65

Answers (1)

Alma Do
Alma Do

Reputation: 37365

You need FIELD function:

SELECT * FROM mall 
WHERE mall_id IN (3331083,33310110,3331080,33310107,33310119,3331410) 
  AND mall_status='1' 
ORDER BY 
  FIELD(mail_id, 3331083,33310110,3331080,33310107,33310119,3331410) 
LIMIT 50 

Upvotes: 6

Related Questions