SELECT
    detResidImfile.*
FROM detRunSummary
JOIN detResidImfile
    USING(det_id,iteration)
WHERE
    ((detRunSummary.data_state = 'goto_cleaned'
      AND detResidImfile.data_state = 'full')
     OR (detRunSummary.data_state = 'goto_scrubbed'
      AND detResidImfile.data_state = 'full')
     OR (detRunSummary.data_state = 'goto_purged'
      AND detResidImfile.data_state = 'full')
     OR detResidImfile.data_state = 'goto_cleaned'
     OR detResidImfile.data_state = 'goto_scrubbed'
     OR detResidImfile.data_state = 'goto_purged')


