SELECT
    sky_id,
    stack_id,
    staticskyRun.workdir,
    staticskyRun.label,
    staticskyRun.data_group,
    staticskyRun.dist_group
FROM staticskyRun 
    JOIN staticskyResult USING(sky_id)
    JOIN staticskyInput USING(sky_id)
    JOIN stackRun USING(stack_id)
    JOIN stackSumSkyfile USING(stack_id)
    LEFT JOIN skycalRun USING(sky_id, stack_id)
WHERE staticskyRun.state = 'full'
    AND staticskyResult.quality = 0

