开发者

mySQL WHERE.. OR query

I want to execute a query on a 开发者_如何学Pythondatabase 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?

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

Thank you for your time!!

Jim


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%';


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

Put a % before and after the keywords.


You can make this smaller like this: SELECT * FROM Event WHERE about REGEXP '(strokestown|arts|day)'


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜