-2

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

CarBuild
-id
-model
-partId

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.

CarProgress
-model
-partId

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.

cool breeze
  • 4,461
  • 5
  • 38
  • 67
  • 4
    Hint: `LEFT JOIN` . . . or `NOT EXISTS` . . . or `NOT IN`. – Gordon Linoff Jun 22 '17 at 18:08
  • 1
    Possible duplicate of [SQL - find records from one table which don't exist in another](https://stackoverflow.com/questions/367863/sql-find-records-from-one-table-which-dont-exist-in-another) – Tab Alleman Jun 22 '17 at 18:29
  • If that duplicate doesn't help, there are lots of others that came up in a simple google search. – Tab Alleman Jun 22 '17 at 18:29

1 Answers1

0
select cb.model, count(*)
from carbuild cb left outer join carprogress cp
on cp.model = cb.model
where cp.model is null
group by cb.model
Esperento57
  • 16,521
  • 3
  • 39
  • 45