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