SELECT DISTINCT
    exp_name, -- return should match pzDoneExp
    camera,
    telescope
FROM (
    SELECT
        pzDoneImfile.*,
        summitExp.imfiles
    FROM pzDoneExp
    JOIN summitExp
        USING(exp_name, camera, telescope)
    LEFT JOIN pzDoneImfile
        USING(exp_name, camera, telescope)
    LEFT JOIN newExp
        ON pzDoneExp.exp_name = newExp.tmp_exp_name
        AND pzDoneExp.camera = newExp.tmp_camera
        AND pzDoneExp.telescope = newExp.tmp_telescope
    WHERE
        newExp.tmp_exp_name IS NULL
        AND newExp.tmp_camera IS NULL
        AND newExp.tmp_telescope IS NULL
    GROUP BY
        pzDoneExp.exp_name,
        pzDoneExp.camera,
        pzDoneExp.telescope
    -- it doesn't matter which field in pzDoneImfile we count as we've already
    -- done a group by
    HAVING
        COUNT(pzDoneImfile.exp_name) = summitExp.imfiles
    ) as Foo
