Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I query for fields containing a given text in MySQL?

SELECT stuff REGEXP 'itunes' as is_itunes; 

In this MySQL query, if "stuff" has the word "itunes" in it, it will mark it as itunes.

However, I want to say "begin with". How can I check for "begin with" instead of anywhere in the text?

like image 257
TIMEX Avatar asked Nov 09 '11 19:11

TIMEX


1 Answers

SELECT ... WHERE stuff LIKE 'itunes%'; 

Here % serves as a wildcard character, so this would match rows with the stuff field equal to any of itunes, itunesfoo, itunes1, ...

More info: SQL LIKE Operator at W3Schools.

like image 64
Marc B Avatar answered Oct 12 '22 09:10

Marc B