SELECT
    addRun.*,
    camProcessedExp.path_base as camroot,
    rawExp.exp_tag,
    rawExp.exp_id,
    rawExp.exp_name,
    rawExp.camera,
    rawExp.telescope,
    rawExp.filelevel
FROM addRun
JOIN camRun
    USING(cam_id)
JOIN camProcessedExp
    USING(cam_id)
JOIN chipRun
    USING(chip_id)
JOIN rawExp
    USING(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 addRun.dvodb IS NOT NULL
    AND addRun.workdir IS NOT NULL
    AND addMask.label IS NULL

