Live data from Hacker News

Query optimization in MySQL with Subqueries

gergerconsulting.blogspot.com

11–15 of 15 posts

Re: Query optimization in MySQL with Subqueries

#14

I'm reading the first query and maybe it's just early but why isn't that subquery just a join? It seems to be acting that way.

By definition all queries using JOINs can be re-written as sub-queries and vice versa. However, in some cases one is more intuitive, convenient or faster than the other. With MySQL you are better off with JOINs in most cases, and use subqueries only when there is a clear benefit and you understand why that would be faster. One exception to this is using a subquery with EXISTS, which is often way faster. While MySQL will tell you that it will look at all matching rows (when looking at EXPLAIN), it will only look at the first one it finds, so practically it ends up being faster.
Post reply on HN