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
ROUND() Function in MySQL The ROUND() function in MySQL is used to round a number to a specified number of decimal places. If no specified number of decimal places is provided for round-off, it rounds off the number to the nearest integer. Syntax ROUND(X, D) Parameter Explanation This method accepts two parameters in the syn
2 min read
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
SUM() Function in MySQL The SUM() function in MySQL is a powerful aggregate function used to calculate the total sum of values in a numeric column. By summing up the values in the specified column, this function helps in generating overall totals and performing calculations that provide meaningful insights from our data. I
4 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
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
SPACE() Function in MySQL SPACE() function in MySQL is used to return a string consisting of specified empty space characters. Syntax : SPACE(num) Parameter : This method accepts one parameter as mentioned above and described below : num : It is an integer which indicates how many spaces are being contained. Returns : It ret
1 min read