Click to See Complete Forum and Search --> : multi table query: what kind of join is this?


sneakyimp
11-08-2006, 02:02 AM
ok...i came up with this query:


SELECT e.id, e.title, e.subheading, e.zip, eta.start_timestamp, eta.end_timestamp, z.city, z.st
FROM demo_events e, demo_event_time_assoc eta, demo_zip_codes z
WHERE eta.event_id = e.id
AND z.zip = e.zip
AND e.active =1
AND (
(
(
eta.start_timestamp >=1162506800
)
AND (
eta.start_timestamp <=1163111600
)
)
OR (
(
eta.start_timestamp <1162506800
)
AND (
eta.end_timestamp >=1162510400
)
)
)
GROUP BY e.id
ORDER BY RAND( )
LIMIT 0 , 10


Is that a join query? What kind of join? Inner? Outer? Cross? Left? Right?

NogDog
11-08-2006, 11:55 AM
I believe it would be considered an inner join, since you're only selecting records where there's an established relation between each table.

sneakyimp
11-08-2006, 02:48 PM
hm. Someone roundly chastised me, saying that it was a poorly constructed query. And this one runs much faster. why?


SELECT e.id, e.title, e.subheading, e.zip, eta.start_timestamp, eta.end_timestamp, z.city, z.st
FROM demo_events e INNER JOIN demo_event_time_assoc eta ON e.id=eta.event_id INNER JOIN demo_zip_codes z ON e.zip=z.zip
WHERE e.active =1 AND
((eta.start_timestamp >=1162506800 AND eta.start_timestamp >=1163111600)
OR
(eta.start_timestamp <1162506800 AND eta.end_timestamp >=1162510400))
ORDER BY RAND() LIMIT 10