Skip to content
Advertisement

Return all data where a value does not exist

I want to know if a job does not have an ‘LI’ CompCode.

SELECT 
    bSLHD.Job, SLCT.SL, APVM.Vendor, APVM.Name, SLCT.CompCode, SLCT.ExpDate 
FROM 
    bSLHD
INNER JOIN 
    SLCT ON bSLHD.SL = SLCT.SL
INNER JOIN 
    APVM ON bSLHD.Vendor = APVM.Vendor

enter image description here

Advertisement

Answer

It sounds like you want aggregation. Something like this:

SELECT bSLHD.Job
FROM bSLHD INNER JOIN
     SLCT
     ON bSLHD.SL = SLCT.SL INNER JOIN
     APVM
     ON bSLHD.Vendor = APVM.Vendor
GROUP BY bSLHD.Job
HAVING SUM(CASE WHEN SLCT.CompCode = 'LI' THEN 1 ELSE 0 END) = 0;
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement