
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL query to search exact word from string?
To search exact word from string, use the below syntax −
select *from yourTableName where yourColumnName regexp '(^|[[:space:]])yourWord([[:space:]]|$)';
Let us first create a table −
mysql> create table DemoTable ( Title text ); Query OK, 0 rows affected (0.23 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('This is the Introduction to Java'); Query OK, 1 row affected (0.05 sec) mysql> insert into DemoTable values('This is the Introduction to MongoDB'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values('This is the Introduction to MySQL'); Query OK, 1 row affected (0.06 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------------------------------------+ | Title | +-------------------------------------+ | This is the Introduction to Java | | This is the Introduction to MongoDB | | This is the Introduction to MySQL | +-------------------------------------+ 3 rows in set (0.00 sec)
Following is the query to search exact word from string.
mysql> select *from DemoTable where Title regexp '(^|[[:space:]])MySQL([[:space:]]|$)';
This will produce the following output −
+-----------------------------------+ | Title | +-----------------------------------+ | This is the Introduction to MySQL | +-----------------------------------+ 1 row in set (0.13 sec)
- Related Articles
- How to search for exact string in MySQL?
- How to search for the exact string value in MySQL?
- How to search a column for an exact string in MySQL?
- MySQL query to check if a string contains a word?
- MySQL query to extract last word from a field?
- MySQL query to extract first word from a field?
- MySQL query to search a string ‘demo’ if someone mistakenly types ‘deom’?
- MySQL query to select a record with two exact values?
- MySQL query to split the string “Learn With Ease” and return the last word?
- MySQL query to search record with apostrophe?
- A single MySQL query to search multiple words from different column values
- How to search specific word in MySQL with RegExp?
- How to remove only the first word from columns values with a MySQL query?
- Find exact string value with COLLATE in MySQL?
- Select first word in a MySQL query?

Advertisements