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