SELECT
    'warp' as stage,
    warpRun.warp_id AS stage_id,
    rawExp.exp_name as run_tag,
    rawExp.obs_mode,
    distTarget.target_id,
    distTarget.clean
FROM warpRun
JOIN fakeRun USING(fake_id)
JOIN camRun ON fakeRun.cam_id = camRun.cam_id
JOIN chipRun USING(chip_id)
JOIN rawExp USING(exp_id)
JOIN distTarget ON distTarget.stage = 'warp' AND rawExp.obs_mode = distTarget.obs_mode
JOIN rcInterest USING(target_id)
LEFT JOIN distRun ON distRun.stage = 'warp' AND (distRun.stage_id = warp_id)
    AND distRun.clean = distTarget.clean
WHERE  distTarget.state = 'enabled'
    AND rcInterest.state = 'enabled'
    AND distRun.dist_id IS NULL
    AND ((warpRun.state = 'full') OR (distTarget.clean AND warpRun.state = 'cleaned'))



