Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mySQL WHERE.. OR query

Tags:

mysql

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?

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

Thank you for your time!!

Jim

like image 464
DukeOfMarmalade Avatar asked Mar 16 '26 20:03

DukeOfMarmalade


2 Answers

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%';
like image 108
Adrian Toman Avatar answered Mar 19 '26 09:03

Adrian Toman


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

Put a % before and after the keywords.

like image 43
marapet Avatar answered Mar 19 '26 10:03

marapet