[Solved] Finding all the missing parts grouped by model
Looking to automatically optimize YOUR SQL query? Start for free.

EverSQL Database Performance Knowledge Base

Finding all the missing parts grouped by model

I have a table that contains all the parts a particular car Model requires:


So to get all the parts for a model you would do:

select * from CarBuild where model=f150

The CarProgress has the cars currently being manufactured and what parts have been installed.


How can i query all the car progress cars that are missing parts grouped by model?

I have the below query so far, should I be doing an left outer join?

select *
from carprogress cp
    inner join carbuild cb on cp.model = cb.model

If someone could explain to me their solution that would be ideal.

How to optimize this SQL query?

The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:

  1. Description of the steps you can take to speed up the query.
  2. The optimal indexes for this query, which you can copy and create in your database.
  3. An automatically re-written query you can copy and execute in your database.
The optimization process and recommendations:
  1. Avoid Selecting Unnecessary Columns (query line: 2): Avoid selecting all columns with the '*' wildcard, unless you intend to use them all. Selecting redundant columns may result in unnecessary performance degradation.
  2. Create Optimal Indexes (modified query below): The recommended indexes are an integral part of this optimization effort and should be created before testing the execution duration of the optimized query.
Optimal indexes for this query:
ALTER TABLE `CarBuild` ADD INDEX `carbuild_idx_model_f150` (`model`,`f150`);
The optimized query:
        CarBuild.model = CarBuild.f150

Related Articles

* original question posted on StackOverflow here.