Reputation: 85
I have two linked tables:
Case_Table: Case_Clients
Client_ID (int, identity)
Case_ID (int, identity) --- Case_ID (int)
Conference_ID (int) Relationship_ID (int)
Other Stuff
Below is the SQL statement to list all records that has a head of household:
SELECT Case_Table.Case_ID,
Case_Table.Conference_ID,
Case_Clients.Client_ID,
Case_Clients.Relationship_ID
FROM Case_Clients INNER JOIN
Case_Table ON Case_Clients.Case_ID = Case_Table.Case_ID
WHERE (Case_Clients.Relationship_ID = 1)
The company requires that each case has a head of household, and we have taken steps to enforce this, but we still have the existing cases that do not have a head of household. I know that I have over 100 cases without a Head of Household (Relationship_ID = 1).
Moving on... what I am trying to do is to list the Conference_ID and Case_ID for each record in Case_Table that does not have a head of household in Case_Clients.
Upvotes: 1
Views: 106
Reputation: 32690
You can use NOT IN
to retrieve any records in CaseTable
that don't have records in Case_Clients
where RelationshipID = 1
(assuming that is the head-of-household record).
SELECT Case_Table.Case_ID, Case_Table.ConferenceID
FROM Case_Table
WHERE CaseTable.Case_ID NOT IN (
SELECT Case_ID
FROM Case_Clients
WHERE RelationshipID = 1
)
Upvotes: 1