- 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
MySQL query not matching due to punctuation?
Use the MySQL LIKE operator to match even when punctuation is present. Let us first create a table−
mysql> create table DemoTable -> ( -> Comments varchar(20) -> ); Query OK, 0 rows affected (1.10 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Good,Morning'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Nice'); Query OK, 1 row affected (0.51 sec) mysql> insert into DemoTable values('good,bye!'); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------------+ | Comments | +--------------+ | Good,Morning | | Nice | | good,bye! | +--------------+ 3 rows in set (0.00 sec)
Following is the query to match even when punctuation is present −
mysql> select *from DemoTable where Comments like '%good%';
This will produce the following output −
+--------------+ | Comments | +--------------+ | Good,Morning | | good,bye! | +--------------+ 2 rows in set (0.00 sec)
Advertisements