-- find the inputs for a new magicDSRun from an existing magicRun
SELECT DISTINCT
    magic_id,
    magicRun.exp_id,
    chip_id,
    cam_id,
    warp_id 
FROM magicRun 
JOIN magicInputSkyfile USING(magic_id)
JOIN diffInputSkyfile USING(diff_id)
JOIN warpRun USING(warp_id)
JOIN fakeRun USING(fake_id)
JOIN camRun USING(cam_id)
JOIN chipRun USING(chip_id)
WHERE template  = 0
AND magic_id = %ld
