# IN(...) ORDER BY ...

**URL:** <https://forums.percona.com/t/in-order-by/267>\
**Category:** Other MySQL® Questions\
**Created:** [April 1, 2007, 10:10am UTC](https://forums.percona.com/t/in-order-by/267 "2007-04-01T10:10:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![morpika](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@morpika](https://forums.percona.com/u/morpika)\
**Post date:** [April 1, 2007, 10:10am UTC](https://forums.percona.com/t/in-order-by/267/1 "2007-04-01T10:10:46Z")

</div>

Hi!

I have a very simple table:

CREATE TABLE `users` (  
`user_id` MEDIUMINT( 7 ) NOT NULL ,  
`user_name` VARCHAR( 30 ) NOT NULL  
)

ALTER TABLE `my_users` ADD INDEX ( `user_id` , `user_name` )

I would like to select specified users ordered by their name!

SELECT \* FROM `users` WHERE `user_id` IN (1, 2, 3, 11, 22, 33) ORDER BY `user_name`

Unfortunately i can’t rid of the filesort (  
Explain says:

id select\_type table type possible\_keys key key\_len ref rows Extra  
1 SIMPLE my\_users range user\_id user\_id 3 NULL 7 Using where; Using index; Using filesort

I have 18.610 rows in the table:

1. Jane
2. John
3. Smith  
ect…

---

<div class="post-metadata">

**Author:** ![Speeple](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@Speeple](https://forums.percona.com/u/Speeple)\
**Post date:** [April 3, 2007, 4:11am UTC](https://forums.percona.com/t/in-order-by/267/2 "2007-04-03T04:11:45Z")

</div>

Don’t think there’s a way of getting round this as index leafs must be skipped in the second branch (`user_name`) due to using a range in the first.
