SELECT DISTINCT
    det_id,
    iteration,
    filelevel
FROM
    (SELECT DISTINCT
	detRun.*
    FROM detRun
    JOIN detRunSummary
        USING(det_id)
    WHERE
       detRun.mode  = 'master'
       AND detRunSummary.accept = 1
    UNION
    SELECT DISTINCT
        *
    FROM detRun
    WHERE
       detRun.mode  = 'register'
    ) as Foo
WHERE
    state = 'stop'
