I have two tables, one with a list of projects and who is assigned to each project, and one with names and information about contractors.
"Projects_table"
Project_ID Contractor_assigned Job_Complete
1 Jim Smith 1
2 John Smith 0
3 Edward Smith 0
4 Smith Smith 1
5 Candle Stick 1
and
"Contractors_Table"
Contractor_ID Name Drywall Insulation
1 Jim Smith 1 0
2 John Smith 0 1
3 Edward Smith 0 1
4 Smith Smith 0 1
5 Jack BeNimble 0 1
6 Jack BeQuick 1 0
7 Candle Stick 0 1
What I need, is to pull an SQL query that gives me a list of the Contractors of a certain type (Drywall or Insulator) who are currently not assigned to any job, so long as that job is also not marked "Complete."
I've tried a few versions of this, but with no success:
SELECT
Name FROM Contractors_Table
WHERE Contractors_Table.Insulation=1
AND Name NOT IN
(SELECT Contractor_assigned FROM Projects_table WHERE `Job_Complete` = 0)
What I'm hoping for output from my above example is to get back:
Jack BeNimble
Candle Stick
Those two Insulators are not currently assigned a job, excluding the "complete" job.