Reputation: 11448
I have
SELECT * FROM hnurl WHERE title LIKE('%text1%')
How do I extend this to also add in things LIKE('%text2%')?
within the same query results?
Upvotes: 2
Views: 89
Reputation: 673
It is also possible with MySQL REGEXP, see the most simplified examples at http://dev.mysql.com/doc/refman/5.1/en/regexp.html, something like:
SELECT * FROM hnurl
WHERE title REGEXP 'text(1|2)'
Variations possible.
Upvotes: 0
Reputation: 838256
Use OR
if you want rows where either or both strings are found:
SELECT * FROM hnurl
WHERE title LIKE '%text1%'
OR title LIKE '%text2%'
Use AND
if you want rows where both strings are found:
SELECT * FROM hnurl
WHERE title LIKE '%text1%'
AND title LIKE '%text2%'
Sidenote: You may also wish to consider using a full-text search or an external text search engine to improve the performance of your queries.
Upvotes: 2
Reputation: 12586
Have you tried:
SELECT * FROM hnurl WHERE title LIKE '%text1%' OR title LIKE '%text2%';
Upvotes: 3