On 25 Feb 2004 at 13:09, Eric Scuccimarra wrote:

> Select        *
> FROM          Table1 as a
>   INNER JOIN Table2 as b ON (a.ID = b.ID or (a.Field1 = b.Field1 and
> a.Field2 = b.Field2)) WHERE   bla bla bla

It's hard to know without seeing the indexes and the full WHERE 
clause, but part of the problem could be that MySQL can't use an 
index for the join because of the "OR".  One possibility would be to 
break in into two queries and use a UNION:

   ( SELECT * FROM Table1 a INNER JOIN Table2 b ON a.ID = b.ID
        WHERE <condition> )
   UNION
   ( SELECT * FROM Table1 a INNER JOIN Table2 b
        ON a.Field1 = b.Field1 AND a.Field2 = b.Field2
        WHERE <condition> )
   ORDER BY <whatever>;

-- 
Keith C. Ivey <[EMAIL PROTECTED]>
Tobacco Documents Online
http://tobaccodocuments.org


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to