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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:05:09+00:00 2026-06-18T03:05:09+00:00

I need to select certain rows from a mysql table that has VARCHAR Primary

  • 0

I need to select certain rows from a mysql table that has VARCHAR Primary Key index ID.

I therefore use a query (but obviously 13,000 ids instead of 3)

SELECT * FROM table1 WHERE ID IN ('id1928383','id3838339','id38383')

For the majority of tables this works well (~0.2s) but for some tables the query takes much longer (~10-11s).

The only thing different about the tables that do not work is they have a larger Data_length? Any ideas how I can speed up the slow query’s?

  • 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-18T03:05:10+00:00Added an answer on June 18, 2026 at 3:05 am

    There are a few things you can do to speed up this query:

    • Use INT instead of VARCHAR for the ID column

    Computers in general are much better with numbers than with strings, so this will speed it up considerably.

    • Add the ID as an index.

    This will create an ordered table with that indexed column, where the searching and ordering will be a LOT faster.

    • Use PDO

    If you are using this with PHP, I recommend you use PDO, since it has a query caching system, and can significantly improve results if there are many identical queries being run. I suppose other programming languages have similar mechanisms.

    • Upgrade MySQL

    For all the software you use it is recommended to use the latest version for many reasons. If I’m not mistaking, there was a performance issue with IN in an older version of MySQL, which was fixed a few version later, but you could be one of the unlucky few that still uses that version.


    That’s about as much as I can help, if you need more help, you will need to post more info (table structure, database structure, programming language, etc).

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

Sidebar

Related Questions

I need to select some rows that don't have certain values in 2 columns.
I need to be able to select a certain range of rows from a
I need to retrieve certain rows from a table depending on certain values in
I need to remove certain rows from a table. Which rows must be deleted
I need to delete an option from a select in certain circumstances. Basically: if(mystatement
I need to select only 20 records from the table and than add pagination
I have a table that I need to use to build a result set
I am working with mysql querying a table that has 12 millions registers that
I have a table with a certain number of columns and a primary key
Okay so I have database and I need to extract only certain rows that

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.