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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:43:08+00:00 2026-06-12T18:43:08+00:00

SELECT MIN(id) FROM mytable WHERE lastname IN(‘Smit’,’Lee’) GROUP BY name Here, for optimise this

  • 0
SELECT MIN(id) 
FROM mytable 
WHERE lastname IN('Smit','Lee') 
GROUP BY name

Here, for optimise this query, index needed (will be useful) column lastname right?
and column name also needed index? or only indexed lastname is enough?

  • 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-12T18:43:09+00:00Added an answer on June 12, 2026 at 6:43 pm

    Both the proposed indexes should help in your situation, however that depends a lot on the data you have and how costly certain operations are considered by the database engine, depending on if you have duplicates for id, which I suspect you don’t and that’s why it’s called id, but if you do an 2-column index on lastname, id or name, id would also help. Ultimately the query optimizer will decide on the strategy to use to fetch data and that will certainly affect many things…
    I propose you try the following and see which is faster

    • index on lastname – likely
    • index on name – a bit less likely
    • index on lastname, name – most likely
    • index on name, lastname – least likely

    Again it really depends on the data but I marked each of those in the order in which I think they should help most for large amounts of data with unique id’s, if your id’s are not unique try combinations with indexes on id as well.

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

Sidebar

Related Questions

For this query SELECT min(date) min_date FROM order_products group by order_id min_date ignores the
I have this query select date(fecha) as day, min(num) as mi from myTable where
Cursor cursor = db.rawQuery(SELECT id,no,name,lastname FROM mytable WHERE + id = (SELECT MIN(id) and
I have the following query: SELECT MIN(myColumn) as myColumn FROM myTable WHERE date(time_stamp) =
Here's the query: SELECT COUNT(*) AS c, MAX(`followers_count`) AS max_fc, MIN(`followers_count`) AS min_fc, MAX(`following_count`)
A database guru has suggested refactoring a query: SELECT * FROM MyTable WHERE UnIndexedDate
I want to echo the record of a 'select min' query. I know how
SELECT Id,Date,Name FROM people WHERE DATEPART(hh,Date) >= 7 AND DATEPART(hh,Date) <= 8 Order by
select tf.Id,tf.Name,tf.LName,tf.Rank,tf.Category where tf.Id not in (select fighter_id from tbl_player_fighter where league_id=91) and tf.Status
Can you do somwthing like this in postresql? select min(column1, column2) as Min, max(column1,

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.