SELECT
    diffRun.skycell_id,
    diffRun.tess_id,
    diffRun.state,
    diffSkyfile.*,
    (SELECT warp_id FROM diffInputSkyfile WHERE diffInputSkyfile.diff_id = diffRun.diff_id
        AND diffInputSkyfile.template = 0 ) AS warp_id_temp_0,
    (SELECT stack_id FROM diffInputSkyfile WHERE diffInputSkyfile.diff_id = diffRun.diff_id
        AND diffInputSkyfile.template = 0 ) AS stack_id_temp_0,
    (SELECT warp_id FROM diffInputSkyfile WHERE diffInputSkyfile.diff_id = diffRun.diff_id
        AND diffInputSkyfile.template = 1 ) AS warp_id_temp_1,
    (SELECT stack_id FROM diffInputSkyfile WHERE diffInputSkyfile.diff_id = diffRun.diff_id
        AND diffInputSkyfile.template = 1 ) AS stack_id_temp_1
FROM diffRun
JOIN diffSkyfile
    USING(diff_id)
JOIN diffInputSkyfile
    ON diffInputSkyfile.diff_id = diffRun.diff_id
    AND diffInputSkyfile.template = 0
JOIN warpRun
    USING(warp_id)
JOIN fakeRun
    USING(fake_id)
JOIN camRun
    USING(cam_id)
JOIN chipRun
    USING(chip_id)
JOIN rawExp
    USING(exp_id)
