Find the records with % character in a LIKE query with MySQL



Let us first create a table −

mysql> create table DemoTable742 (Value varchar(100)); Query OK, 0 rows affected (2.91 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable742 values('632535MIT'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable742 values('US%UK'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable742 values('56%78'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable742 values('%_1234'); Query OK, 1 row affected (0.09 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable742;

This will produce the following output -

+-----------+ | Value | +-----------+ | 632535MIT | | US%UK | | 56%78 | | %_1234 | +-----------+ 4 rows in set (0.00 sec)

Following is the query to find records with % character using LIKE query −

mysql> select *from DemoTable742 where Value LIKE '%\%%';

This will produce the following output -

+--------+ | Value | +--------+ | US%UK | | 56%78 | | %_1234 | +--------+ 3 rows in set (0.00 sec)
Updated on: 2019-08-22T08:06:08+05:30

227 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements