title: MySQL JOIN using either NON-NULL column to reference another table
body: <p>I have 2 tables filled automatically by cronjobs (an events table and a location table with the addresses of the events. Because both feeds are different, sometimes the events are linked to the locations via location_id1, but sometimes with location_id2, like such:</p>
  
  <pre><code>locations table:
  id   imported_id1   imported_id2   address
  1          NULL          20           xx
  2          10            NULL         xx
  ...
  
  
  events table:
  id   location_id1   location_id2   some_data
  1       NULL           20           xx
  2       10             NULL         xx
  ...
  </code></pre>
  
  <p>To select the events and get the correct address to the location it's linked to, I tried a <code>JOIN</code> like this, but the <code>OR</code> makes the query run SO MUCH slower:</p>
  
  <pre><code>SELECT * FROM events
  JOIN locations ON
      events.location_id1 = locations.limported_id1
      OR events.location_id2 = locations.limported_id2;
  </code></pre>
  
  <p>Anyone has a better way to query this?</p>