Select Query on INDEXED TABLE not using INDEX

explain SELECT count(*) FROM employees e WHERE e.empno>1000 AND e.level > 2 AND (‘2010-06-29 00:00:00’-INTERVAL 2 day) >e.hire_date;
±—±------------±------±-----±-----------------------------------±-----±--------±-----±-------±------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
±—±------------±------±-----±-----------------------------------±-----±--------±-----±-------±------------+
| 1 | SIMPLE | e | ALL |empno,level,hire_date| NULL | NULL | NULL | 916114 | Using where |
±—±------------±------±-----±-----------------------------------±-----±--------±-----±-------±------------+
1 row in set (0.00 sec)

IN ABOVE CASE ,i have indexed empno,level,hire_date attributes of employees table
but above Query scans entire table and instead of looking at indexed values

mysql can use only one index for any single retrieval operation, and none of your indexes is useful

try adding a compound index

ALTER TABLE employees
ADD INDEX combo_ix ( empno, level )

:slight_smile: