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?
你有没有尝试过:
SELECT * FROM hnurl WHERE title LIKE '%text1%' OR title LIKE '%text2%';
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.
您可以添加
... OR title LIKE '%text2%'
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.