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

  • SEARCH
  • Home
  • 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 9141893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:42:19+00:00 2026-06-17T09:42:19+00:00

I have query that uses order-by group-by select count(*),filed2 from table1 where field1>x group

  • 0

I have query that uses order-by group-by

select count(*),filed2
from table1 where field1>x group by filed2 order by  count(*) desc

what are the best indexes for this query.
sholud I index filed1,field2 seprate or together?

  • 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-17T09:42:20+00:00Added an answer on June 17, 2026 at 9:42 am

    You should create the index with both columns in two different orders

    ALTER TABLE table1 ADD INDEX field1_field2_ndx (field1,field2);
    ALTER TABLE table1 ADD INDEX field2_field1_ndx (field2,field1);
    

    You should not create individual indexes because making the index with both columns will cause the query to pass through the index only to satisfy the query. It would never need to touch the table.

    Even if you made individual indexes, the Query Optimizer would choose the two column index anyway.

    Now that you have the two indexes, just trust the Query Optimizer to select the correct index. Based on the query, the EXPLAIN plan would choose the field2_field1_ndx index.

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

Sidebar

Related Questions

I have a query that looks like this SELECT * from myTable WHERE Date
I have a query that uses for xml explit to return XML result. select
I have a query that uses ORDER BY ASC and as such 0's come
I have a query that uses the outputs(R1,R2) of two sub queries in order
I have used a JOIN to put together a query that uses columns from
I have this MySQL query that I'd like to optimize: SELECT min(`topic_id`) FROM `gallery_topics`
I have a combobox query that uses parameters from a parent item. When I
I have this query: SELECT foo.*, COUNT(archive.pkey) as archivedCount FROM ( SELECT type, count(active.pkey)
I have a query that uses a where clause. At times, this may be
I have a mysql query that uses union to join multiple queries into one

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.