SELECT DISTINCT
    warpSkyCellMap.warp_id,
    warpSkyCellMap.skycell_id,
    warpSkyCellMap.tess_id,
    warpRun.fake_id,
    camRun.cam_id,
    rawExp.camera,
    warpRun.workdir
FROM warpRun
JOIN warpSkyCellMap
    USING(warp_id)
JOIN fakeRun
    USING(fake_id)
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 warpSkyfile
    ON warpRun.warp_id = warpSkyfile.warp_id
    AND warpSkyCellMap.skycell_id = warpSkyfile.skycell_id
    AND warpSkyCellMap.tess_id = warpSkyfile.tess_id
LEFT JOIN warpMask
    ON warpRun.label = warpMask.label
WHERE
    warpRun.state = 'run'
    AND fakeRun.state = 'stop'
    AND camRun.state = 'stop'
    AND chipRun.state = 'full'
    AND warpSkyfile.warp_id IS NULL
    AND warpSkyfile.skycell_id IS NULL
    AND warpSkyfile.tess_id IS NULL
    AND warpSkyCellMap.fault = 0
    AND warpMask.label IS NULL
