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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:53:30+00:00 2026-05-23T02:53:30+00:00

This query goes against a single table. The table has 60 attributes called attribute1

  • 0

This query goes against a single table. The table has 60 attributes called “attribute1” through “attribute60”, and they are all of type:

varchar(255)

There is also a column called “brand_id” that is:

int(11)

The following key exists on the table:

brand_id, attribute1, attribute2, attribute3

The query is as follows:

SELECT distinct attribute1
from brands b inner join product_applications pa on pa.brand_id = b.id
where b.id in (1,372,373,374,375,376,378,381,452,
               453,454,455,456,457,458,461,474,476,
               544,480,563,508,512,513,516,517,519,520,521,
               522,524,525,527,528,529,533,538,539,540,542,
               546,547,548,555,556,557,642,643,644,645,646,
               647,648,649,650,651,652,653,654,655)

It takes over 10 seconds. The table has 5,735,673 rows.

This query needs to take no more than 2 seconds. I cannot figure out how to write it, or if I need some sort of alternate table structure, to do this. Can anyone offer a recommendation?

I used to use an IN in the WHERE clause, but it was recommended in another forum that this ugly way was faster because of the join. I don’t really know what that means, but it IS faster, but still incredibly slow.

+----+-------------+-------+-------+----------------------------------------+--------------------+---------+-----------+-------+-------------------------------------------+
| id | select_type | table | type  | possible_keys                          | key                | key_len | ref       | rows  | Extra                                     |
+----+-------------+-------+-------+----------------------------------------+--------------------+---------+-----------+-------+-------------------------------------------+
|  1 | SIMPLE      | b     | range | PRIMARY                                | PRIMARY            | 4       | NULL      |    60 | Using where; Using index; Using temporary | 
|  1 | SIMPLE      | pa    | ref   | brand_search_index,parttype_search_idx | brand_search_index | 5       | mcp5.b.id | 57356 | Using where; Using index                  | 
+----+-------------+-------+-------+----------------------------------------+--------------------+---------+-----------+-------+-------------------------------------------+
2 rows in set (0.04 sec)
  • 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-05-23T02:53:31+00:00Added an answer on May 23, 2026 at 2:53 am

    This seems like an odd query, so I might be missing something, but I think you can do this with an IN clause:

    SELECT distinct attribute1
    from product_applications pa WHERE brand_id IN (1, 372, ..., 655)
    

    I would think this is faster — it’s certainly cleaner — but if not you might need to add a little detail about indexes, maybe an EXPLAIN QUERY, etc.

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

Sidebar

Related Questions

I got this error running a query that goes against 2 tables with combined
Hey, I have a table called products that has a relationship with itself. This
How can I get this query to work where it goes through the checks
I have this query statement and want to only get records that has a
I'm using this query to get all employees of {clients with name starting with
I am working on optimizing a SQL query that goes against a very wide
When trying to execute this query my mysql server cpu usage goes to 100%
i have a query that goes like this: $get_feed_amount = mysql_query( SELECT COUNT(*) as
This query works great: var pageObject = (from op in db.ObjectPermissions join pg in
This query is related to this one I asked yesterday. I have a radio

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.