Is there a faster way to do an inner join with an
OR clause. I have a query that looks something like this:
INNER JOIN (select u_id, b_id from t1) AS t2 ON t2.u_id = t1.u_id OR (t2.b_id = t1.b_id AND t1.u_id is null)
but it takes over 6 seconds.
I think there's a way to replace the
OR with two joins, but I could use a hand figuring it out.
Here's a SQL fiddle of my use case: http://sqlfiddle.com/#!12/cee6e/2
Basically, I'm looking for user_id and browser_id of an event with the name 'foo' (and in a specific time range) that happened sometime before 'bar'. First I search for the 'foo' events in a specific date range, and then join those onto the 'bar' events by matching the user_ids, or if no user_id, using the browser_ids.
One data constraint: Any events with matching browser_ids will also have matching user_ids (or nulls).