This can do what you need, except you made as small mistake in the end of the query:
SELECT id FROM table2
WHERE id NOT IN(SELECT id FROM table1)
UNION
SELECT id FROM table2
WHERE id IN(SELECT id FROM table1 WHERE distance=0)
I replaced 'and' with 'where'.