-- 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
    camPendingExp.*,
    rawExp.exp_tag,
    rawExp.exp_id,
    rawExp.camera,
    rawExp.telescope,
    rawExp.filelevel
FROM camPendingExp
JOIN chipProcessedExp
    USING(chip_id)
JOIN rawExp
    ON chipProcessedExp.exp_tag = rawExp.exp_tag
LEFT JOIN camProcessedExp
    ON camPendingExp.cam_id = camProcessedExp.cam_id
LEFT JOIN camMask
    ON camPendingExp.label = camMask.label
WHERE
    camProcessedExp.cam_id IS NULL
    AND camMask.label IS NULL
