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