I am working on a report that needs to display people who have not done certain training. I have a query that shows people's names and the raining they've done, and another query that shows the entire list of training.
Query #1:
select distinct a.ID, b.Name, b.Descript, b.Code
from Roster a
join SkillCheckOff b on b.Id = a.ID
order by a.ID, b.Descript
Query #2:
select Descript, Code
from LookupTable
where Type = 'TRTSkillCheckOff'
order by Descript
Final result:
Name Descript
-----------------------
John Training A
Abbie Training A
Mike Training B
...
Basically, if the descript from query #2 is not found from query #1 for each user, the final query needs to display the name and the missing training. Please help.
Based on the answers provided, I think the below query comes close.
with roster as (
select ID
from Roster
),
skills as (
select Descript, Code from LookupTable where Type = 'TRTSkillCheckOff'
)
select r.ID, s.Descript
from roster r cross join skills s
EXCEPT
select name, Descript
from SkillCheckOff
I think using EXCEPT works here.
NOT EXISTS