Home > Database > Mysql Tutorial > How to Perform Exact Word Searches in MySQL?

How to Perform Exact Word Searches in MySQL?

Barbara Streisand
Release: 2025-01-14 08:35:44
Original
993 people have browsed it

How to Perform Exact Word Searches in MySQL?

Performing a "whole word match" search in MySQL

When searching for keywords in a MySQL database, you usually need to match the entire word exactly, rather than a partial match. This is especially useful when searching for terms like "rid" as it ensures there is no match for "arid".

To achieve whole-word matching, use the REGEXP operator with word boundary markers. The [[:<:]] and [[:>:]] tags define word boundaries.

<code class="language-sql">SELECT *
FROM table
WHERE keywords REGEXP '[[:<:]]rid[[:>:]]'</code>
Copy after login

For MySQL 8.0.4 and later, the standard word boundary tag b should be used instead.

<code class="language-sql">SELECT *
FROM table
WHERE keywords REGEXP '\brid\b'</code>
Copy after login

Remember that for REGEXP mode to work properly, a backslash needs to be escaped with another backslash. By using this technique, you can perform exact whole-word matching in MySQL, ensuring the accuracy of your search results.

The above is the detailed content of How to Perform Exact Word Searches in MySQL?. 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