I'm trying to join a subset of data from one table with data in another table (example below), and from a performance standpoint, i'm wondering what the best way to do this is, and what is most scalable.
The table I am trying to join looks like this (the other tables are already in the query).
vid kid uid 1 34 12 1 34 15 2 22 18 2 34 18 2 22 15
My query is like this
SELECT * FROM similar RIGHT OUTER JOIN(SELECT event.stuff, eventdate.stuffshows FROM events JOIN evendate ON events.eid=eventdate.eid WHERE location= 'Paris' AND event.date BETWEEN '2009-08-14' AND '2009-08-17' GROUP BY event.date ORDER BY event.date LIMIT 0 , 5 ) mystuff ON event.bid = similar.id AND event.date=similar.date
I think I can make it into
SELECT * FROM similar RIGHT OUTER JOIN(SELECT event.stuff, eventdate.stuffshows FROM events JOIN evendate ON events.eid=eventdate.eid WHERE user.vid=events.vid AND user.uid=15 AND user.kid=22 location= 'Paris' AND event.date BETWEEN '2009-08-14' AND '2009-08-17' GROUP BY event.date ORDER BY event.date LIMIT 0 , 5 ) mystuff ON event.bid = similar.id AND event.date=similar.date
My concern is that I'm kinda mixing a join with a where. Is it worth it for performance to set a second JOIN for user.vid=events.vid? Or is it better to do a WHERE rather than a join?
Any suggestions on this?