SOUNDEX() Function in MySQL
Last Updated :
07 Oct, 2020
SOUNDEX() function in MySQL is used to return a phonetic representation of a string. The phonetic represents the way the string will sound. The SOUNDEX function helps to compare words that are spelled differently, but sound alike in English.
Syntax :
SOUNDEX(str)
Parameter :
SOUNDEX() function accepts one parameter as mentioned above and described below.
- str : The string whose phonetic representation we want to know.
Returns :
It returns phonetic representation of given string.
Note :
- This function, as currently implemented, is intended to work well with strings that are in the English language only. Strings in other languages may not produce reliable results.
- This function is not guaranteed to provide consistent results with strings that use multibyte character sets, including utf-8.
Example-1 :
Finding the SOUNDEX string of ‘geeksforgeeks’ using SOUNDEX Function.
SELECT SOUNDEX('geeksforgeeks') AS SoundexString;
Output :
Example-2 :
Finding the SOUNDEX string of ‘Hello’ using SOUNDEX Function.
SELECT SOUNDEX('Hello') AS SoundexString;
Output :
Example-3 :
SOUNDEX Function can also be used to find the SOUNDEX string for column data. To demonstrate create a table named Student.
CREATE TABLE Student
(
Student_id INT AUTO_INCREMENT,
Student_name VARCHAR(100) NOT NULL,
Student_Class VARCHAR(20) NOT NULL,
PRIMARY KEY(Student_id )
);
Now inserting some data to the Student table :
INSERT INTO Student
(Student_name, Student_Class )
VALUES
('Ananya Majumdar', 'IX'),
('Anushka Samanta', 'X' ),
('Aniket Sharma', 'XI' ),
('Anik Das', 'X' ),
('Riya Jain', 'IX' ),
('Tapan Samanta', 'X' ),
('Deepak Sharma', 'X' ),
('Ankana Jana', 'XII'),
('Shreya Ghosh', 'X') ;
So, the Student Table is as follows.
mysql> select * from Student;
+------------+-----------------+---------------+
| Student_id | Student_name | Student_Class |
+------------+-----------------+---------------+
| 1 | Ananya Majumdar | IX |
| 2 | Anushka Samanta | X |
| 3 | Aniket Sharma | XI |
| 4 | Anik Das | X |
| 5 | Riya Jain | IX |
| 6 | Tapan Samanta | X |
| 7 | Deepak Sharma | X |
| 8 | Ankana Jana | XII |
| 9 | Shreya Ghosh | X |
+------------+-----------------+---------------+
9 rows in set (0.00 sec)
Now, we are going to find SOUNDEX string for column Student_name.
SELECT
Student_id, Student_name,
SOUNDEX( Student_name) AS SoundexSname,
Student_Class FROM Student ;
Output :
+------------+-----------------+--------------+---------------+
| Student_id | Student_name | SoundexSname | Student_Class |
+------------+-----------------+--------------+---------------+
| 1 | Ananya Majumdar | A52536 | IX |
| 2 | Anushka Samanta | A5253 | X |
| 3 | Aniket Sharma | A523265 | XI |
| 4 | Anik Das | A5232 | X |
| 5 | Riya Jain | R250 | IX |
| 6 | Tapan Samanta | T15253 | X |
| 7 | Deepak Sharma | D1265 | X |
| 8 | Ankana Jana | A52525 | XII |
| 9 | Shreya Ghosh | S620 | X |
+------------+-----------------+--------------+---------------+
Similar Reads
SECOND() Function in MySQL
SECOND() function in MySQL is used to return the second portion of a specified time or date-time value. The first parameter in this function will be the date/Date Time. This function returns the seconds from the given date value. The return value (seconds) will be in the range of 0 to 59. In this fu
2 min read
SUBDATE() function in MySQL
SUBDATE() function in MySQL is used to subtracts a time value (as interval) from a given date. Syntax : SUBDATE(date, INTERVAL expr unit) Parameter : This function accepts three parameters as given below : date : First specified date. expr : The value of the time/date interval to subtract. unit : Th
2 min read
ORD() Function in MySQL
ORD() function in MySQL is used to find the code of the leftmost character in a string . If the leftmost character is not a multibyte character, it returns ASCII value. And if the leftmost character of the string str is a multibyte character, ORD returns the code for that character, calculated from
3 min read
SOUNDS LIKE Function in MySQL
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 be
2 min read
PLSQL | SOUNDEX Function
The PLSQL SOUNDEX function is used for returning a phonetic representation of a string. The phonetic represents the way the string will sound. The PLSQL SOUNDEX function helps to compare words that are spelled differently, but sound alike in English. The SOUNDEX function accepts one parameter input_
2 min read
SIGN() Function in MySQL
SIGN() function in MySQL is used to return the sign of the given number. It returns 1 if the number is positive, -1 if the number is negative and 0 for zero. Syntax : SIGN(X) Parameter : SIGN() function accepts one parameter as input and will give you the results in values like Positive(+1),Negative
1 min read
SYSDATE() function in MySQL
SYSDATE() function in MySQL is used to return the current date and time in YYYY-MM-DD HH:MM:SS or YYYYMMDDHHMMSS.uuuuuu format depending on the context of the function. Syntax : SYSDATE() Parameter : This method does not accept any parameter. Returns : It returns the current date and time value. Exa
1 min read
POW() Function in MySQL
POW() function : This function in MySQL is used to return a results after raising a specified exponent number to a specified base number. For example if the base is 5 and exponent is 2, this will return a result of 25. Syntax : SELECT POW(x, y); Parameter : This method accepts two parameters as give
1 min read
QUOTE () function in MySQL
QUOTE() : This function in MySQL is used to return a result that can be used as a properly escaped data value in an SQL statement. The string is returned enclosed by single quotation marks and with each instance of backslash (\), single quote ('), ASCII NULL, and Control+Z preceded by a backslash. I
2 min read
TAN() Function in MySQL
TAN() function : This function in MySQL is used to return the tangent of a specified number. In any right triangle, the tangent of an angle is the length of the opposite side divided by the length of the adjacent side. Similarly, this can also be defined as tangent of x is the sine of x divided by t
1 min read