Line in SQL that contains a row of specific words
question:
You need a SQL query that returns rows in the table with all specified fields containing one or more words in the given list. These words can appear in the fields in any order.
Solution:
To retrieve lines in a field containing any specified word, use the LIKE operator with wildcards:
SELECT *
FROM MyTable
WHERE Column1 LIKE '%word1%'
OR Column1 LIKE '%word2%'
OR Column1 LIKE '%word3%'
To retrieve lines with fields containing all specified words, use the AND condition:
SELECT *
FROM MyTable
WHERE Column1 LIKE '%word1%'
AND Column1 LIKE '%word2%'
AND Column1 LIKE '%word3%'
Notice:
When searching for multiple words, consider using full-text search for performance, most major databases support full-text search. The specific implementation of full-text search depends on the database type.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3