
- 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 use MySQL LIKE query to search a column value with % in it?
To search a column value with %, the syntax is as follows −
select * from yourTableName where yourColumnName LIKE '\%%';
Let us first create a table −
mysql> create table DemoTable1497 -> ( -> Name varchar(20) -> ); Query OK, 0 rows affected (0.55 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1497 values('%JohnSmith'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1497 values('DavidMiller'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1497 values('CarolTaylor%'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1497 values('%DavidMiller'); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select −
mysql> select * from DemoTable1497;
This will produce the following output −
+--------------+ | Name | +--------------+ | %JohnSmith | | DavidMiller | | CarolTaylor% | | %DavidMiller | +--------------+ 4 rows in set (0.00 sec)
Here is the query to use like query to search a column value with % in it −
mysql> select * from DemoTable1497 -> where Name LIKE '\%%';
This will produce the following output −
+--------------+ | Name | +--------------+ | %JohnSmith | | %DavidMiller | +--------------+ 2 rows in set (0.00 sec)
- Related Articles
- MySQL query for text search with LIKE and OR to fetch records
- MySQL query to replace a column value
- MySQL query to remove a value with only numbers in a column
- How to use quotes correctly while using LIKE with search variable in MySQL in Java?
- MySQL SELECT to add a new column to a query and give it a value?
- Use LIKE % to fetch multiple values in a single MySQL query
- MySQL query to search within the last 5 characters in a column?
- Search record with a specific value in MySQL using LIKE or REGEXP?
- MySQL query to search record with apostrophe?
- MySQL query to find same value on multiple fields with LIKE operator?
- Is it possible to use UPDATE query with LIMIT in MySQL?
- Add user defined value to a column in a MySQL query?
- How to use a single MySQL query to count column values ignoring null?
- MySQL query to find sum of fields with same column value?
- Can we use “LIKE concat()” in a MySQL query?

Advertisements