On 2/10/07, Brodie Thiesfield <[EMAIL PROTECTED]> wrote:

Hi,

I'm looking for some SQL advice. I have a query which is used as the
base of a filter. At the moment I am using:

SELECT * FROM table WHERE (1=? OR foo=?);

The actual query is more complex and uses multiple of the constructions
in this WHERE clause. If I wanted to select on the foo column then I
would bind (0, 'desired-foo'). If I didn't then I would bind (1, '').
There is an index on the foo column, but this construction precludes the
use of it even when I have a specific foo that I want. The idea behind
this was to prepare a single select query, and then just reuse it all of
the time.


Why not have multiple statements? The 'or' clause is going to prevent that
one
from using an index effectively. It might be simpler but the performance
won't be good.

--
The PixAddixImage Collector suite:
http://groups-beta.google.com/group/pixaddix

SqliteImporter and SqliteReplicator: Command line utilities for Sqlite
http://www.reddawn.net/~jsprenkl/Sqlite

Cthulhu Bucks!
http://www.cthulhubucks.com

Reply via email to