SELECT
    detResidImfile.*,
    rawExp.camera
FROM detRunSummary
JOIN detResidImfile
    USING(det_id,iteration)
JOIN detInputExp
    USING(det_id,iteration,exp_id)
JOIN rawExp
    USING(exp_id)
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')


