SELECT DISTINCT
    diff_id
FROM (
    SELECT
        COUNT(diffInputSkyfile.skycell_id), COUNT(diffSkyfile.skycell_id),
        diffSkyfile.*
    FROM diffRun
    JOIN diffInputSkyfile USING(diff_id)
    LEFT JOIN diffSkyfile USING(diff_id, skycell_id)
    WHERE 
        diffRun.state = 'new'
    GROUP BY
        diffInputSkyfile.diff_id
    HAVING
        COUNT(diffInputSkyfile.skycell_id) = COUNT(diffSkyfile.skycell_id)
        AND SUM(diffSkyfile.fault) = 0
    ) as Foo
