MySQL Forums
Forum List  »  Optimizer & Parser

Re: Subqueries too slow
Posted by: Andreas Schlicker
Date: February 07, 2006 08:38AM

Jay,

I just tried your suggested query.

In order to get the right results, I also had to dublicate the join on the b table:

SELECT a.id, a.acc, a.name
FROM a
INNER JOIN b
ON a.id = b.a_id
INNER JOIN c
ON b.c_id=c.id
AND c.acc="X"
INNER JOIN b as b2
ON a.id = b2.a_id
INNER JOIN c as c2
ON b2.c_id=c2.id
WHERE c2.acc="Y";

However, this makes it easier to generate the SQL automatically. Most important, it's much faster than the original query.

Thank you very much.

Options: ReplyQuote


Subject
Views
Written By
Posted
5414
February 06, 2006 11:08AM
2745
February 06, 2006 11:54AM
2519
February 06, 2006 02:17PM
2533
February 07, 2006 07:06AM
Re: Subqueries too slow
2537
February 07, 2006 08:38AM
2619
February 10, 2006 03:18AM
2198
February 10, 2006 08:51AM
2248
February 10, 2006 09:49AM
2458
February 10, 2006 10:43AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.