[thelist] MySQL "OR"

Luther, Ron Ron.Luther at hp.com
Thu Sep 8 09:53:22 CDT 2005

Andrew Kamm asked about long "OR" SQL:

>>Is it proper to execute a rather long SQL query in MySQL?  
>>I'm not aware of a reason this wouldn't work (unless there 
>>is simply a limit on the length of a queries), but I'm not 
>>sure if it's bad form or if the DB would respond poorly.

Hi Andrew,

Yeah you can execute a "long" query, and sometimes you need to.

>From a cursory glance, however, it looks like you are looking 
to return results either for 'new' advertisers, or a group of 
advertisers having some property in common, (same industry or 
something for example).

If that is the case, then I believe you would get better 
performance if you created a separate table of 'new' advertisers 
or a table of all advertisers containing several fields for 
categorization values, (one of which could be a 'new' flag for 
example).  You could then modify your SQL to join in the new 
table and add a simple 'where' clause on one of the category 

[Table joins are generally a lot more powerful and performance 
friendly than zillions of 'OR' statements.]

OTOH, if you are returning results for all advertisers, then a 
'group by' might come closer to what you are trying to do than 
explicitly naming each advertiser in the 'where' section.



More information about the thelist mailing list