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
5564
February 06, 2006 11:08AM
2811
February 06, 2006 11:54AM
2591
February 06, 2006 02:17PM
2602
February 07, 2006 07:06AM
Re: Subqueries too slow
2604
February 07, 2006 08:38AM
2696
February 10, 2006 03:18AM
2262
February 10, 2006 08:51AM
2329
February 10, 2006 09:49AM
2541
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.