>> SELECT          id_team,
>>                         sum(IF(m.id_visitor = t.id_team,m.visitor_score,
>> m.home_score)) AS But_pour,
>>                         sum(IF(m.id_visitor != t.id_team,m.visitor_score,
>> m.home_score)) AS But_contre
>> FROM             tab_teams t, tab_matchs m
>> WHERE           t.id_level =4
>> AND                (m.id_visitor = t.id_team OR m.id_home = t.id_team) AND
>> m.season = 2
>> GROUP BY     id_team;
>>

Try rewriting this SQL query into a UNION all statement, by removing the OR
condition in the WHERE clause, like:

SELECT
        <fields>
FROM
        <tables>
WHERE
        m.id_visitor=t.id_team AND m.season=2

UNION ALL

SELECT
        <fields>
FROM
        <tables>
WHERE
        m.id_home=t.id_team AND m.season=2


At least from what I know of Oracle this can speed up the query by orders
of magnitudes and it maybe does the trick with mySQL, too. UNION ALL is
supported with mySQL >= 4.x.


Best regards
... Ralph ...



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to