IMHO SQL Server can choose itself (unless being told) what is the best index to use for the query.
Ok
What about something like this (pseudo code):
select __a from tbl where __a not in
(
select __b from tbl
)
(let’s say we have index_1 which is for (__a) and index_2 which is for (__b)
Will SQL Server still use one index at execution or multiple indexes together…?
First, create your tables:
Then create two indexes:
Now populate with some data:
Now run your query and turn actual execution plan on. You will see something like this, showing that yes, both indexes are used (in fact the index on __b is used both for data retrieval in the subquery and as a seek to eliminate rows):
A more efficient way to write your query would be:
Now here’s your whole plan (again, both indexes are used, but notice how there are much fewer operations):