
- 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
How to search a column for an exact string in MySQL?
For exact string, you need to use wildcard ‘%’ with LIKE operator −
select *from yourTableName where binary yourColumnName LIKE '%yourStringValue%';
Let us first create a table −
mysql> create table DemoTable( Name varchar(20) ); Query OK, 0 rows affected (1.93 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (1.11 sec) mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable values('Adam'); Query OK, 1 row affected (1.19 sec) mysql> insert into DemoTable values('JOHN'); Query OK, 1 row affected (0.60 sec) mysql> insert into DemoTable values('ADAM'); Query OK, 1 row affected (0.43 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------+ | Name | +-------+ | Chris | | John | | Adam | | JOHN | | ADAM | +-------+ 5 rows in set (0.00 sec)
Following is the query to search a column for an exact string in SQL −
mysql> select *from DemoTable where binary Name LIKE '%JOHN%';
This will produce the following output −
+------+ | Name | +------+ | JOHN | +------+ 1 row in set (0.09 sec)
- Related Articles
- How to search for exact string in MySQL?
- How to search for the exact string value in MySQL?
- MySQL query to search exact word from string?
- Search for a string within text column in MySQL?
- How to search a MySQL table for a specific string?
- How to search for a string in an ArrayList in java?
- Quickly search for a string in MySQL database?
- How to search for a string in JavaScript?
- How to search for a pattern in a Java string?
- How to search a string for a pattern in JavaScript?
- Search for specific characters within a string with MySQL?
- How to search on a MySQL varchar column using a number?
- How to search for ^ character in a MySQL table?
- MySQL query to conduct a basic search for a specific last name in a column
- Find exact string value with COLLATE in MySQL?

Advertisements