- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements
To Continue Learning Please Login
Login with Google