-- select * from chipPendingExp
-- where exp_tag is not in chipProcessedExp
-- where exp_tag is not in chipPendingImfile
-- where the number of entries in chipProccessedImfile matches the .imfiles
-- entry in rawExp
SELECT DISTINCT
    chipPendingExp.*,
    rawExp.imfiles,
    chipProcessedImfile.class_id
FROM chipPendingExp
JOIN rawExp
    ON chipPendingExp.exp_tag = rawExp.exp_tag
LEFT JOIN chipProcessedExp
    ON chipPendingExp.chip_id = chipProcessedExp.chip_id
LEFT JOIN chipPendingImfile
    ON chipPendingExp.chip_id = chipPendingImfile.chip_id
LEFT JOIN chipProcessedImfile
    ON chipPendingExp.chip_id = chipProcessedImfile.chip_id
WHERE
    chipProcessedExp.chip_id IS NULL
    AND chipPendingImfile.chip_id IS NULL
    AND chipProcessedImfile.chip_id IS NOT NULL
GROUP BY
    chipPendingExp.chip_id
HAVING rawExp.imfiles = COUNT(chipProcessedImfile.class_id)
