Page 1 of 1

Simplifying a WHERE clause

Posted: Tue Feb 24, 2009 3:07 pm
by Reviresco
(MYSQL) - Is there a way to simplify or use a shortcut on multiple OR operators in a WHERE clause?

Instead of:

Code: Select all

WHERE field1 = '$x' OR field2 = '$x' OR field3 = '$x' OR field4 = '$x'
A way to combine those four fields into one big "OR"?

(Also, same question for REGEXP instead of "="?)

Re: Simplifying a WHERE clause

Posted: Tue Feb 24, 2009 4:04 pm
by Chris Corbyn
See if this works:

[sql]WHERE '$x' IN (field1, field2, field3, field4)[/sql]

IN() works for values, I've never tried it with fields like that but logically it should work.

Re: Simplifying a WHERE clause

Posted: Tue Feb 24, 2009 4:46 pm
by Reviresco
Yep that works (for the "=" anyway, not regexp).

For regexp, I think I'll try fulltext indexing instead.