PHP_USER1
PHP_USER1

Reputation: 628

Where in clause using order by to get the result

SELECT * FROM `fz_users` WHERE `id` in ('6', '1', '30', '34', '11', '3', '2', '7', '4', '24', '221')

I am using this query to show the user data and 6,1,30.... are the ids of the user but my problem is that i need in the same order like I am giving in it ie 6,1,30,34,11,3,2

Upvotes: 0

Views: 35

Answers (1)

Jayesh Chitroda
Jayesh Chitroda

Reputation: 5049

Try

SELECT * FROM your_table
WHERE id IN ('6', '1', '30', '34', '11', '3', '2', '7', '4', '24', '221')
ORDER BY FIELD(id,'6', '1', '30', '34', '11', '3', '2', '7', '4', '24', '221');

Upvotes: 4

Related Questions