Modify query to avoid a full table scan on MySQL

Follow-up to Redmine Feature #832.

Query execution plan before modification:

![before](https://cloud.githubusercontent.com/assets/8998989/5221068/d50bc310-7671-11e4-8cc5-6c941b46203b.png)

Query execution plan after modification:

![after](https://cloud.githubusercontent.com/assets/8998989/5221080/ffded83e-7671-11e4-9c01-b0d349626642.png)