> Sasha,
> I don't see how I can rewrite it without LEFT JOIN. I tried to rewrite it as
> (which should be faster I think):
>
> SELECT Sum(JoinedLinkedInfo.ValueNum) AS Amount, LinkedInfo.Record_ID FROM
> JoinedLinkedInfo LEFT JOIN LinkedInfo USING (Link_ID) WHERE
> JoinedLinkedInfo.Field_ID=21 GROUP BY LinkedInfo.Record_ID;
>
Marc:
I am afraid I don't have the time to sit down and think
through your query to figure things out, but in the time
I have I can offer a generic approach that will
hopefully help.
1) Decide what it is that you actually need from the
query
2) Think of a number of ways to accompilsh it, including
using intermediate results stored in a temporary table,
eliminate the ones that are obvously inefficient, and
try each one of them on a smaller data set to make sure
that they work correctly.
3) Try it on a bigger data set to see which gives the
best performance
4) Throught the entire process, try to think like the
database engine. If you see a more efficient way of
doing things than what the query optimizer decides on,
try re-writing the query, maybe breaking it down into
several and storing intermediate results, in such a way
that the optimizer will see how to do it best.
--
Sasha Pachev
http://www.sashanet.com/ (home)
http://www.direct1.com/ (work)