It seems that you have a decent answer in the comments, but to throw one more opportunity in the ring, you can run both requests and combine them.
select * from table1 as a LEFT JOIN table2 as b on a.id1 = b.id1 union select * from table1 as a LEFT JOIN table2 as b on a.id2 = b.id2
The union will remove any duplicates between sets and return records where any condition is true, just like yours or operator. Performance is wise, combining is probably a bit slower, but gives you easier control over sets. For example, if you want set 2 to return results when id1 is null, just add it to the where clause. Anyway, hope this helps.
source share