SELECT DISTINCT
    'diff' as stage,
    diffRun.diff_id AS stage_id,
    diffRun.magicked,
    rawExp.exp_name as run_tag,
    distTarget.label,
    distTarget.target_id,
    distTarget.clean
FROM diffRun
JOIN diffInputSkyfile using(diff_id)
JOIN warpRun on diffInputSkyfile.warp1 = warpRun.warp_id
JOIN fakeRun USING(fake_id)
JOIN camRun USING(cam_id)
JOIN chipRun USING(chip_id)
JOIN rawExp USING(exp_id)
JOIN distTarget ON distTarget.stage = 'diff'
    AND diffRun.label = distTarget.label
    AND distTarget.filter = rawExp.filter
JOIN rcInterest USING(target_id)
LEFT JOIN distRun ON distRun.stage = 'diff' AND (distRun.stage_id = diff_id)
    AND distRun.clean = distTarget.clean
    -- JOIN hook %s
WHERE  distTarget.state = 'enabled'
    AND rcInterest.state = 'enabled'
    AND distRun.dist_id IS NULL
    AND ((diffRun.state = 'full') OR (distTarget.clean AND diffRun.state = 'cleaned'))



