SELECT
    addRun.*,
    rawExp.exp_tag,
    rawExp.exp_id,
    rawExp.exp_name,
    rawExp.camera,
    rawExp.telescope,
    rawExp.filelevel
FROM addRun
JOIN camRun
    USING(cam_id)
JOIN chipRun
    USING(chip_id)
JOIN chipProcessedImfile
    USING(chip_id)
JOIN rawExp
    ON chipRun.exp_id = rawExp.exp_id
LEFT JOIN addProcessedExp
    USING(add_id)
LEFT JOIN addMask
    ON addRun.label = addMask.label
WHERE
    camRun.state = 'full'
    AND ((addRun.state = 'new' AND addProcessedExp.add_id IS NULL) OR addRun.state = 'update')
    AND addMask.label IS NULL

