SELECT
    detResidExp.*
FROM detRunSummary
JOIN detResidExp
    USING(det_id,iteration)
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')