List:General Discussion« Previous MessageNext Message »
From:Christian Mack Date:July 17 1999 3:40pm
Subject:Re: query optimization..
View as plain text  
Alex Krohn wrote:
> 
> Hi,
> 
> Thanks for the suggestion!
> 
> >> SELECT d.*
> >> FROM Data as d LEFT JOIN Alt as a ON d.ID = a.DataID
> >> WHERE d.Category = 5 OR a.Category = 5
> >
> >> Any ideas would be really appreciated!
> >
> >This OR clause is prorably is bad. I think you get much quicker result
> >if you do two different queries:
> 
> I suppose I'm still stuck to sorting the two result sets together manually?
> I can do this really quick (both queries will use indexes):
> 
> SELECT * FROM Data WHERE Category = 5
> 
> and
> 
> SELECT d.* FROM Data, Alt WHERE Alt.Category = 5 AND Alt.LinkID =
> Data.LinkID
> 
> However, then I'm stuck trying to put them into the proper order (trying to
> get mysql to do it, not my app).
> 
> Cheers,
> 
> Alex

Hi Alex

If you need some sorting on this, use a temporary table.
1) Create a temporary table (e.g. temp31650865) with the structure of the desired results.
2) Use multiple "INSERT INTO temp31650865 SELECT ..." queries to fill the above temporary
table.
3) Get the sorted result you search for with a "SELECT ... ORDER BY ..." on this temporary
table.
4) Drop the temporary table.

This will be faster, than querying an OR-clause.

Tschau
Christian

PS: Sorry for the late answer, I was on vacation.

Thread
query optimization..Alex Krohn11 Jul
  • Re: query optimization..Tõnu Samuel11 Jul
    • Re: query optimization..Paul DuBois11 Jul
  • Re: query optimization..Tõnu Samuel14 Jul
Re: query optimization..Alex Krohn11 Jul
  • Re: query optimization..Christian Mack17 Jul