mySQL WHERE .. OR 查询
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5442342/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mySQL WHERE.. OR query
提问by DukeOfMarmalade
I want to execute a query on a database to select all rows in the 'Event' table where the 'about' section has any of the following words in it: strokestown, arts, day. My query, shown below is only getting rows that have the first word, strokestown in them. How do I make it search for all words?
我想对数据库执行查询以选择“事件”表中“关于”部分包含以下任何单词的所有行:strokestown、arts、day。我的查询(如下所示)仅获取包含第一个单词 strokestown 的行。如何让它搜索所有单词?
SELECT *
FROM Event
WHERE about LIKE 'strokestown%'
OR about LIKE 'arts%'
OR about LIKE 'day%';
Thank you for your time!!
感谢您的时间!!
Jim
吉姆
回答by Adrian Toman
Place the wildcard character, '%', at the start as well as the end of the your search terms:
将通配符“%”放在搜索词的开头和结尾:
SELECT *
FROM Event
WHERE about LIKE '%strokestown%'
OR about LIKE '%arts%'
OR about LIKE '%day%';
回答by marapet
SELECT * FROM Event
WHERE about LIKE '%strokestown%'
OR about LIKE '%arts%'
OR about LIKE '%day%'
Put a % before and after the keywords.
在关键字前后放置一个 %。
回答by Andrew Hymanman
You can make this smaller like this: SELECT * FROM Event WHERE about REGEXP '(strokestown|arts|day)'
你可以像这样把它变小: SELECT * FROM Event WHERE about REGEXP '(strokestown|arts|day)'
回答by Tufan Bar?? Y?ld?r?m
SELECT * FROM Event WHERE about LIKE '%strokestown%' OR about LIKE '%arts%' OR about LIKE '%day%';