I have a query that uses a foreign key and other column(say c1) in where clause. By default, foreign key is indexed. When i add index to c1 and run explain command, the query takes up only foreign key for searching, not the c1 which is also indexed.
I'm not supposed to create a single index for both foreign key and other column. I tried reading comments related to indexing, any suggestions would be really grateful.
Table: Student: Id, Name, year, Class_tutor_id
ClassTutor: Id, name
Select name from Student where Class_tutor_id in (Select id from ClassTutor where name='Sally') and year>=200 and year<=2006;
I have created index in year field. Class_tutor_id is the foreign key referring to ClassTutor table id. When i execute the query with explain command, Under "Keys" column i get the foreign key Class_tutor_id, but in "Possible keys" column, I get foreign key, primary key, year