- Trending Categories
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 to search a string ‘demo’ if someone mistakenly types ‘deom’?
For this, you can use SOUND along with the LIKE operator. Let us first create a table −
mysql> create table DemoTable -> ( -> Name varchar(20) -> ); Query OK, 0 rows affected (0.95 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values('Adam'); Query OK, 1 row affected (0.33 sec) mysql> insert into DemoTable values('Johm'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable values('Carol'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('SAMSUNG'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('SAMSUMG'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------+ | Name | +---------+ | John | | Adam | | Johm | | Carol | | SAMSUNG | | SAMSUMG | +---------+ 6 rows in set (0.00 sec)
Here is the query to search a string which is inserted in the table as a typo, for example, “deom” for “demo”, ‘samsumg” for “samsung” −
mysql> select *from DemoTable where Name SOUNDS LIKE 'samsung';
This will produce the following output −
+---------+ | Name | +---------+ | SAMSUNG | | SAMSUMG | +---------+ 2 rows in set (0.00 sec)
Advertisements