[thelist] MySQL "OR"
Andrew Kamm
akamm at demicooper.com
Fri Sep 9 11:59:33 CDT 2005
Thanks everyone for the responses -- just wanted to follow up. Using the
"IN" operator worked great for the current setup. I knew looping an OR that
long seemed a little unnecessary (and I was obviously unfamiliar with IN!).
I'm also going to attempt to rework a table solution as RonL suggested.
It's part of a searching function that is creating some temporary tables
anyhow, so that may fit in quite well.
thanks!
--
Andrew Kamm
On 9/8/05 9:53 AM, "Luther, Ron" <Ron.Luther at hp.com> wrote:
> 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
> fields.
>
> [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.
>
>
> HTH,
>
> RonL.
> --
>
More information about the thelist
mailing list