SELECT DISTINCT
    diffRun.diff_id,
    diffRun.workdir,
    diffRun.skycell_id,
    diffRun.tess_id,
    rawExp.camera
FROM diffRun
JOIN diffInputSkyfile
    USING(diff_id)
JOIN warpSkyfile
    ON  diffInputSkyfile.warp_id    = warpSkyfile.warp_id
    AND diffInputSkyfile.skycell_id = warpSkyfile.skycell_id
    AND diffInputSkyfile.tess_id    = warpSkyfile.tess_id
JOIN warpRun
    ON warpRun.warp_id = warpSkyfile.warp_id
JOIN fakeRun
    USING(fake_id)
JOIN camRun
    USING(cam_id)
JOIN chipRun
    USING(chip_id)
JOIN rawExp
    USING(exp_id)
LEFT JOIN diffSkyfile
    ON diffInputSkyfile.diff_id = diffSkyfile.diff_id
WHERE
  diffRun.state = 'new'
  AND warpRun.state = 'full'
  AND fakeRun.state = 'full'
  AND camRun.state = 'full'
  AND chipRun.state = 'full'
  AND diffSkyfile.diff_id IS NULL
