Re: doing query for an array of strings On Sat, 19 Jan 2008 10:04:14 +0100, yataaa wrote:
> Peter H. Coffin schrieb:
>
>> ... WHERE ColumnName IN ('val1', 'val2', 'val3' ... );
>
> Oh great, thats exactly what I wanted.
>
>> is the right way to construct that. There is a way to do it without
>> knowing the match values beforehand, but Paul yells when people talk
>> about it. You might be able to put your match terms into a temporary
>> table and join against it.
>
> Yes, I thought about that, too. But I couldn't figure out the way to do
> that.. Is that kind of "unclean" mySQL, or why does he yell?
There's a couple of reasons to avoid it: it's not standard SQL so it
won't port to any other DBMS. It's overloading a specific task to do
something else, which can make the application fragile. But probably the
more important bit is that it encourages bad design by enabling multiple
values inside a given column-row to be usable. The bit above requires
you to know, at the time that you're writing the query, what values
you're searching for, and even if you're writing the query at runtime in
an application language (like PHP or C), you can at least capture the
query as run and SEE all the conditions that are being used to select
your data set.
--
94. When arresting prisoners, my guards will not allow them to stop and grab a
useless trinket of purely sentimental value.
--Peter Anspach's list of things to do as an Evil Overlord |