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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:09:15+00:00 2026-05-22T20:09:15+00:00

I have a table with 60 attributes in it, attribute1..attribute60. The database engine in

  • 0

I have a table with 60 attributes in it, attribute1..attribute60. The database engine in MySQL and the table engine is MyISAM. The query is as follows:

SELECT DISTINCT attribute1
  FROM `product_applications`
 WHERE `product_applications`.`brand_id` NOT IN (642, 630, 513, 637, 632,
                                                 556, 548, 628, 651, 660,
                                                 648, 557, 650, 624, 652,
                                                 636, 546, 662, 634, 629,
                                                 657, 638, 658, 659, 661, 625)

I use a NOT IN, because that list is significantly smaller than the IN list.

I have created the following index:

brand_id, attribute1, attribute2, attribute3, attribute4

A DESC reveals that this index is being selected, but it looks like it is still looking at the whole table because I see the whole row count in the “rows” column:

6732948

In the “extra” column I have:

Using where; Using index; Using temporary

This query is taking over 7 seconds. I am looking at all different options here, including breaking the table up.

UPDATE:

I was able to cut the query time in half with the clever use of the UNION ALL noted by my friend below. Also, this is a dynamically generated query, so none of the temporary table options that some of you have offered, while an excellent idea, were available to me.

  • 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-22T20:09:16+00:00Added an answer on May 22, 2026 at 8:09 pm

    Previously, the following used a LEFT JOIN — but the OP reversed the logic to use an INNER JOIN:

       SELECT DISTINCT 
              t.attribute1
         FROM PRODUCT_APPLICATIONS t
         JOIN (SELECT 642 AS brand_id
               UNION ALL 
               SELECT 630
               UNION ALL 
               SELECT 513
               UNION ALL 
               SELECT 637
               UNION ALL 
               SELECT 632           
               UNION ALL 
               SELECT 556
               UNION ALL 
               SELECT 548
               UNION ALL 
               SELECT 628
               UNION ALL 
               SELECT 651
               UNION ALL 
               SELECT 660
               UNION ALL 
               SELECT 648
               UNION ALL 
               SELECT 557
               UNION ALL 
               SELECT 650
               UNION ALL 
               SELECT 624
               UNION ALL 
               SELECT 652
               UNION ALL 
               SELECT 636
               UNION ALL 
               SELECT 546
               UNION ALL 
               SELECT 662
               UNION ALL 
               SELECT 634
               UNION ALL 
               SELECT 629
               UNION ALL 
               SELECT 657
               UNION ALL 
               SELECT 638
               UNION ALL 
               SELECT 658
               UNION ALL 
               SELECT 659
               UNION ALL 
               SELECT 661
               UNION ALL 
               SELECT 625) x ON x.brand_id = t.brand_id
    

    You could consider populating a temp table, to use in place of the derived one you see in my answer.

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

Sidebar

Related Questions

I have a MySQL database containing the following tables: Table: Professor Attributes: ID, ProfessorName
I want to read database tables with Attributes. I have Table in database and
I have two tables from two different databases. For example: Table: Articles1 - Database:
I have a table called product_attributes in a MySQL Database. It consists of a
I have a basic property bag table that stores attributes about my primary table
I have table rows of data in html being filled from a CGI application.
I'm designing a product database where products can have very different attributes depending on
I access a a postgres table using SQLAlchemy. I want a query to have
I have a PRODUCTS table, and each product can have multiple attributes so I
I am using CakePHP framework with MySQL database and I have problem in saving

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.