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 8287825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:09:03+00:00 2026-06-08T12:09:03+00:00

Lets say I have following query: SELECT * FROM table WHERE id = 1

  • 0

Lets say I have following query:

SELECT * FROM table WHERE id = 1 ORDER BY name

Is it better to add multi-column index (id and name) or separate index for name?

  • 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-06-08T12:09:05+00:00Added an answer on June 8, 2026 at 12:09 pm

    That depends on the cardinality of id. If it has a high cardinality (meaning, few rows share the same value of id) an index on id is a good idea. The database will do a seek for id and look the few matching rows up in the base table.

    If half the table has the same id, the query will result in an index scan. Note that since you’re using *, a multi-column index would not be used unless it contains all columns in the table. So this can be made faster only with an index containing all columns that is sorted on (name).

    At the end of the day, it’s often best not to create an index at all, until you encounter specific performance problems. The specifics will allow you to test & measure whether your proposed index will work. That’s almost always better than trying to guess the right indexes.

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

Sidebar

Related Questions

Lets say I have the following query. SELECT stringdata FROM table ORDER BY FIELDS(
Let's say I have the following query: SELECT anInteger FROM table; How do I
Let's say I have the following SQL query SELECT id, name, title, description, time
Let's say I have following query: SELECT Id, Name, ForeignKeyId, (SELECT TOP (1) FtName
Lets say I have the following script k <- as.numeric(readline(Start Index: )) tot <-
Lets say I have this SQL statements: ALTER TABLE dbo.[tbl] ALTER COLUMN col1 varchar(300)
I have the following mysql table called test. lets say it has the data
I have the following SQL query: select ID, COLUMN1, COLUMN2 from (select ID, COLUMN1,
I have the following query: SELECT DISTINCT sites.site_id, sites.site_name, sites.site_url, earnings.cust_id FROM sites, earnings
Let's assume I have the following query: SELECT address FROM addresses a, names n

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.