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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:26:54+00:00 2026-06-01T11:26:54+00:00

I have a users table with 450,000 records. The table structure is as so:

  • 0

I have a users table with 450,000 records. The table structure is as so:

  UserID Int(11) Primary Key
  Firstname (50) Varchar
  Lastname  (50) Varchar

I also need to check two other table to see if the UserID is in those tables. (the structure is a bit different, but the table have the same UserID)
I am running this sub query below, and is running very slow. Appreciate a second set of eyes to offer up a fresh perspective to help run a bit faster…

SELECT 
`Users`.`Firstname`, 
`Users`.`Lastname`, 
`Users`.`UserID` 
FROM `Users`
WHERE `Users`.`UserID` IN  (SELECT `admin`.`UserID` FROM `admin` WHERE `admin`.`UserID`=`User`.`UserID`)
AND `Users`.`UserID` IN  (SELECT `elite`.`UserID` FROM `elite` WHERE `elite`.`UserID`=`Users`.`UserID`)
AND `Users`.`Lastname` LIKE '%smith%'
  • 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-01T11:26:56+00:00Added an answer on June 1, 2026 at 11:26 am

    The absolutely most important thing when optimizing queries in MySQL is to ensure you have the appropriate indexes. Check what indexes you have (using SHOW INDEX), and what indexes the query is using (using EXPLAIN SELECT). Indexes are absolutely vital for good performance once your tables get large.

    In particular you should make sure that you have an index on the UserID column in all three tables. I’d also suggest adding a foreign key contraint if that is appropriate in your situation.

    However if you have already checked you have the correct indexes and you still aren’t getting appropriate performance, you can try using joins instead instead of subselects:

    SELECT 
        Users.Firstname, 
        Users.Lastname, 
        Users.UserID 
    FROM Users
    JOIN admin USING (UserID)
    JOIN elite USING (UserID)
    WHERE Users.Lastname LIKE '%smith%'
    

    Note that LIKE '%smith%' is unable to use an index efficiently. You should avoid LIKE expressions that start with a wildcard if possible.

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

Sidebar

Related Questions

I have a table users which has a primary key userid and a datetime
I'm using SQL-Server 2005 Standard. I have Users table with following columns: userID(int), userImage(varchar),
I have a table [Users] with the following columns: INT SmallDateTime Bit Bit [UserId],
I have a table users with primary index userId . Currently, each user has
I'm using sql-server 2005 and ASP.NET with C#. I have Users table with userId(int),
well I have a table create table usersnew ( user1 varchar (50) primary key,
I have a database table called users with a primary key of user_id for
I'm using Sql-Server 2005 I have Users table with userID and gender. I want
Using Sql-Server 2005. I have Users table with 3 columns. userID, parentUserID and userEmail.
I have a table that needs to be given a new primary key, as

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.