mySQL WHERE ..或查询

时间:2011-03-26 12:33:54

标签: mysql

我想在数据库上执行查询以选择“事件”表中的所有行,其中“about”部分中包含以下任何单词:strokestown,arts,day。我的查询(如下所示)仅获取具有第一个单词的行,其中包含strokestown。如何让它搜索所有单词?

SELECT *
  FROM Event
 WHERE about LIKE 'strokestown%'
    OR about LIKE 'arts%'
    OR about LIKE 'day%';

感谢您的时间!!

吉姆

4 个答案:

答案 0 :(得分:8)

将通配符'%'放在搜索字词的开头和结尾处:

SELECT * 
FROM Event 
WHERE about LIKE '%strokestown%' 
OR about LIKE '%arts%' 
OR about LIKE '%day%';

答案 1 :(得分:6)

SELECT * FROM Event
WHERE about LIKE '%strokestown%'
    OR about LIKE '%arts%'
    OR about LIKE '%day%'

在关键字之前和之后加上%。

答案 2 :(得分:4)

你可以这样缩小:SELECT * FROM Event WHERE about REGEXP '(strokestown|arts|day)'

答案 3 :(得分:1)

SELECT * FROM Event WHERE about LIKE '%strokestown%' OR about LIKE '%arts%' OR about LIKE '%day%';