How do I query for fields containing a given text in MySQL?
Solution 1:
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.
Solution 2:
Add the caret symbol, it represents the beginning of the string:
SELECT stuff REGEXP '^itunes' as is_itunes;
However, LIKE 'itunes%'
as suggested by Marc should be a lot faster, especially if your indexes are set up correctly.
Solution 3:
SELECT ... WHERE LEFT(stuff, 6) = 'itunes';