-- this query is used by both camtool -pendingexp & camtool -addprocessedexp it
-- does a little more work then is necessary for -addprocessed but it seems
-- "cleaner" to use the same query for both cases 
SELECT * FROM
    (SELECT
        camRun.*,
        rawExp.exp_tag,
        rawExp.exp_id,
        rawExp.exp_name,
        rawExp.camera,
        rawExp.telescope,
        rawExp.filelevel
    FROM camRun
    JOIN chipRun
        USING(chip_id)
--  JOIN chipProcessedImfile
--      USING(chip_id)
    JOIN rawExp
        USING(exp_id)
--      ON chipProcessedImfile.exp_id = rawExp.exp_id
    LEFT JOIN camProcessedExp
        USING(cam_id)
    LEFT JOIN camMask
        ON camRun.label = camMask.label
    WHERE
        chipRun.state = 'full'
        AND ((camRun.state = 'new' AND camProcessedExp.cam_id IS NULL)
            OR camRun.state = 'update')
        AND camMask.label IS NULL
    ) as Foo
