Open In App
Related Articles

SOUNDS LIKE Function in MySQL

Improve Article
Improve
Save Article
Save
Like Article
Like

SOUNDS LIKE :
This function in MySQL is used to compare the Soundex codes of a given two string expressions. It is used as SOUNDEX(expr1) = SOUNDEX(expr2) to retrieve strings that sound similar.

Syntax :

expr1 SOUNDS LIKE expr2

Parameter :
It accepts two parameter as mentioned above and described below.

  • expr1 – The first string which we want to compare.
  • expr2 –The second string which we want to compare.

Returns :
It compares the Soundex code of two string values and returns the output.

Example-1 :
Comparing similar two given string using SOUNDS LIKE Function.

SELECT 'geeks' SOUNDS LIKE 'geeks' 
as Result;

Output :

Result

    1

Example-2 :
Comparing similar two given strings using SOUNDS LIKE Function.

SELECT 'geeks' SOUNDS LIKE 'for' 
as Result;

Output :

Result

    0

Example-3 :
The following example shows returns all the rows which contain an Employee name whose first name sounds like ‘Sayan’.

CREATE TABLE Employee
(
Employee_id INT AUTO_INCREMENT,  
First_name VARCHAR(100) NOT NULL,
Last_name VARCHAR(100) NOT NULL,
Joining_Date DATE NOT NULL,
PRIMARY KEY(Employee_id )
);

Inserting some data to the Employee table :

INSERT INTO Employee
(First_name ,Last_name , Joining_Date )
VALUES
('Sayantan', 'Majumdar', '2000-01-11'),
('Anushka', 'Samanta', '2002-11-10' ),
('Sayan', 'Sharma', '2005-06-11' ),
('Shayari', 'Das', '2008-01-21' ),
('Sayani', 'Jain', '2008-02-01' ),
('Tapan', 'Samanta', '2010-01-11' ),
('Deepak', 'Sharma', '2014-12-01'  ),
('Ankana', 'Jana', '2018-08-17'),
('Shreya', 'Ghosh', '2020-09-10') ;

So, the Employee Table is as follows.

select * from Employee ;

Output :

Employee_id First_name Last_name Joining_Date
1 Sayantan Majumdar 2000-01-11
2 Anushka Samanta 2002-11-10
3 Sayan Sharma 2005-06-11
4 Shayari Das 2008-01-21
5 Sayani Jain 2008-02-01
6 Tapan Samanta 2010-01-11
7 Deepak Sharma 2014-12-01
8 Ankana Jana 2018-08-17
9 Shreya Ghosh 2020-09-10

Now, we are going to check those employee whose first name sounds like ‘sayan’.

SELECT * FROM Employee 
WHERE First_name SOUNDS LIKE 'Sayan' ;

Output :

Employee_id First_name Last_name Joining_Date
3 Sayan Sharma 2005-06-11
5 Sayani Jain 2008-02-01
Unlock the Power of Placement Preparation!
Feeling lost in OS, DBMS, CN, SQL, and DSA chaos? Our Complete Interview Preparation Course is the ultimate guide to conquer placements. Trusted by over 100,000+ geeks, this course is your roadmap to interview triumph.
Ready to dive in? Explore our Free Demo Content and join our Complete Interview Preparation course.

Last Updated : 14 Dec, 2020
Like Article
Save Article
Previous
Next
Similar Reads