Home >Database >Mysql Tutorial >How to Select SQL Records Containing Multiple Specific Words?

How to Select SQL Records Containing Multiple Specific Words?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2025-01-15 17:51:44688browse

How to Select SQL Records Containing Multiple Specific Words?

SQL SELECT statement WHERE clause contains multiple words

Question:

You need a SQL query that retrieves records where a specified column contains more than one specific word, regardless of word order.

Solution:

There are two ways to achieve this:

1. Contains any word

To include records containing any specified word, use the following query structure:

<code class="language-sql">SELECT * FROM [表名]
WHERE [列名] LIKE '%[单词1]%'
OR [列名] LIKE '%[单词2]%'
...
OR [列名] LIKE '%[单词N]%'</code>

2. Contains all words

To include records containing all specified words, use the following structure:

<code class="language-sql">SELECT * FROM [表名]
WHERE [列名] LIKE '%[单词1]%'
AND [列名] LIKE '%[单词2]%'
...
AND [列名] LIKE '%[单词N]%'</code>

Note: To improve performance, consider using database type-specific full-text search capabilities.

The above is the detailed content of How to Select SQL Records Containing Multiple Specific Words?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn