Link to home
Start Free TrialLog in
Avatar of spectrumcare
spectrumcare

asked on

MYSQL query not using multiple column index

I have a multiple column index on a mysql table. Let's say the index is (first, second, third). When I run this query

SELECT first, second, third
FROM table

EXPLAIN shows me it is using the index. But if I run the following query

SELECT first, second, third, fourth
FROM table

it is not using the index.

Do I need all the columns that I am selecting to be in the index?
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of spectrumcare
spectrumcare

ASKER

Sorry, I am using  order by FIRST. But for whatever reason, it is not using the index if I try to query a field that is not included in the index. I've even tried forcing the index.
Could the issue be that I have an autonumber column that is forced to have a primary index on it?
I've got it working now. I'll give you the points for answering.