MySQL query to select a specific string with special characters

MySQLi DatabaseMySQL

Let us first create a table −

mysql> create table DemoTable
(
   Title text
);
Query OK, 0 rows affected (0.66 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('MySQL');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable values('MongoDB\'s');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable values('MySQL\'s');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable values('Java\'s');
Query OK, 1 row affected (0.24 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+-----------+
| Title     |
+-----------+
| MySQL     |
| MongoDB's |
| MySQL's   |
| Java's    |
+-----------+
4 rows in set (0.00 sec)

Here is the query to select string with special character −

mysql> select *from DemoTable where replace(Title, '''', '') like '%MySQLs%';

This will produce the following output −

+---------+
| Title   |
+---------+
| MySQL's |
+---------+
1 row in set (0.00 sec)
raja
Published on 01-Oct-2019 12:23:12
Advertisements