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
Release: 2025-01-15 17:51:44
Original
646 people have browsed it

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>
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template