Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6922417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:24:11+00:00 2026-05-27T10:24:11+00:00

I found that the if I query the table with less than or greater

  • 0

I found that the if I query the table with less than or greater than operator, sql server indexes do not work properly.

Say I have a simple table (TestTable) with only 2 columns like this:

Column Name, column type, primary Key, index
iID,         int,         yes,         cluster index
iCount,      int,         no,          non-cluster index
name,        nvarchar(255), no,        no index

Now, I query the table by this:

SELECT * FROM TestTable WHERE iCount = 10.

Very good, Sql server will use the non-cluster index for column iCount to retrieve the result.

However, if I query the table by this:

SELECT * FROM TestTable WHERE iCount < 10,

Sql server will do a index scan over the cluster index for the iID to retrieve the result.

I am wondering why sql server is not able to use proper index when I use less than or greater than operator in the query.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:24:12+00:00Added an answer on May 27, 2026 at 10:24 am

    If the table has very few rows, it is cheaper for SQL Server to scan the clustered index rather than using the non-clustered index and then doing a lookup for the rest of the columns in the clustered index. If that’s the case, change the query to SELECT iCount FROM… and you should see the query plan change to using the index as you are expecting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an inherent cost to using inline-table-valued functions in SQL Server 2008 that
I would like to delete all the rows found by that query: SELECT cart_abandon.*
Taking over some code from my predecessor and I found a query that uses
I found something that works with updating one field at here: http://www.karlrixon.co.uk/articles/sql/update-multiple-rows-with-different-values-and-a-single-sql-query/ UPDATE person
I am trying to return the result that I found in my query to
Indexing is used to improve performance of sql query but I always found it
I have a problem with a query that works in phpmyadmin but not with
I'm executing a query like this select field from table; In that query, there
I am using SQL Server 2008-R2 Express Edition. I wrote the query shown below
In a database I have less than 200,000 records in a table, and in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.