Fetch records containing a specific character twice in MySQL


Let us first create a table −

mysql> create table DemoTable
   -> (
   -> Words text
   -> );
Query OK, 0 rows affected (0.54 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('Ever');
Query OK, 1 row affected (0.18 sec)

mysql> insert into DemoTable values('Forever');
Query OK, 1 row affected (0.13 sec)

mysql> insert into DemoTable values('Good');
Query OK, 1 row affected (0.14 sec)

mysql> insert into DemoTable values('Never');
Query OK, 1 row affected (0.12 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

Output

+---------+
| Words   |
+---------+
| Ever    |
| Forever |
| Good    |
| Never   |
+---------+
4 rows in set (0.00 sec)

Following is the query to fetch records containing a specific character twice. Here, we are searching for records with the character “e” appearing 2 times −

mysql> select *from DemoTable where Words LIKE '%e%e%';

Output

+---------+
| Words   |
+---------+
| Ever    |
| Forever |
| Never   |
+---------+
3 rows in set (0.00 sec)
raja
Published on 10-Jul-2019 16:59:44
Advertisements