SELECT
    detResidExp.*,
    rawExp.camera
FROM detRunSummary
JOIN detResidExp
    USING(det_id,iteration)
JOIN detInputExp
     USING(det_id,iteration,exp_id)
JOIN rawExp
    USING(exp_id)
WHERE
    ((detRunSummary.data_state = 'goto_cleaned'
      AND detResidExp.data_state = 'full')
     OR (detRunSummary.data_state = 'goto_scrubbed'
         AND detResidExp.data_state = 'full')
     OR (detRunSummary.data_state = 'goto_purged'
         AND detResidExp.data_state = 'full')
     OR detResidExp.data_state = 'goto_cleaned'
     OR detResidExp.data_state = 'goto_scrubbed'
     OR detResidExp.data_state = 'goto_purged')
