SELECT
    chipProcessedImfile.*,
    chipRun.state,
    chipRun.workdir,
    chipRun.label,
    chipRun.reduction,
    chipRun.expgroup,
    chipRun.dvodb,
    chipRun.tess_id,
    chipRun.end_stage
FROM chipRun
JOIN chipProcessedImfile
    USING(chip_id)
WHERE
    ((chipRun.state = 'goto_cleaned' AND chipProcessedImfile.data_state = 'full')
OR 
    (chipRun.state = 'goto_purged' AND chipProcessedImfile.data_state != 'purged'))
