【发布时间】:2012-03-22 20:45:31
【问题描述】:
我正在使用 Regex 搜索我的 MySQL 数据库,如下所示:
$search 看起来像这样 WORD1|WORD2|WORD3
$regexp = "REGEXP '[[:<:]][[:alpha:]]*($search)[[:alpha:]]*[[:>:]]'";
SELECT * FROM
zitate
WHERE
UPPER(`field1`) $regexp OR UPPER(`field2`) $regexp OR UPPER(`field3`)
现在,正如预期的那样,我得到了 $search 与 field1 或 field2 或 field3 匹配的每个条目
但我只想接收 WORD1、WORD2 和 WORD3 在每列中匹配的条目,而不是在整个表中。
我知道这是因为我的查询中出现了OR,但有什么比这样写更好:
WHERE
UPPER(`field1`) $regexp AND UPPER(`field2`) $regexp
OR
UPPER(`field2`) $regexp AND UPPER(`field3`) $regexp
OR
UPPER(`field1`) $regexp AND UPPER(`field3`) $regexp
OR
UPPER(`field1`) $regexp AND UPPER(`field2`) $regexp AND UPPER(`field3`) $regexp
或者我应该使用这个AND、OR 查询吗?
感谢任何提示和答案!
【问题讨论】:
-
真的没人能给我建议吗?