1

I have a database table users

users

 id       | username       |is_active
----------|----------------|------------
 1        | chinu          | 1  
 2        | sradhanjali    | 1
 3        | User3          | 0

I have a list of user ids in an array that is array(2,3,1) I want to get records below order.

 id       | username       |is_active
----------|----------------|------------
 2        | sradhanjali    | 1  
 3        | User3          | 0
 1        | chinu          | 1

I have tried -

Query:

select * from users where id IN(2,3,1)

But this query does not return the correct result which I want.

If anybody knows how to write this query. Please help me.

Thanks

Chinmay235
  • 3,236
  • 8
  • 62
  • 93

1 Answers1

3

you can use order by field

select * from users where id IN(2,3,1) order by FIELD(id,2, 3, 1) ;