×

MySQL SOUNDEX() function

In this context, we will learn how we can use the MySQL SOUNDEX() function with proper syntax and good examples.

Introduction of MySQL SOUNDEX() function

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 compare words spelled differently but sound alike in English.

Syntax of the MySQL SOUNDEX() function

The syntax of the MySQL SOUNDEX() function is given as follows:

SOUNDEX(str)

Parameters or arguments used in MySQL SOUNDEX() function:

Only one parameter is accepted by the SOUNDEX() function in MySQL, which is given as mentioned above and described below.

Str: The string whose phonetic representation we want to know.

Returns:

It will return a phonetic representation of the given string.

Some important points of MySQL SOUNDEX function:

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.

Application used for SOUNDEX() function:

The SOUNDEX() function can be used in the given below MySQL versions.:

  • MySQL 5.7
  • MySQL 5.6
  • MySQL 5.5
  • MySQL 5.1
  • MySQL 5.0
  • MySQL 4.1
  • MySQL 4.0
  • MySQL 3.23

Examples of MySQL SOUNDEX() function:

Now we will look into some MySQL SOUNDEX() function examples and will explore how we can use the SOUNDEX function in MySQL.

Example 1:

In this example, we will Find the SOUNDEX string of 'JAVATPOINT' using the SOUNDEX Function in MySQL.

SELECT SOUNDEX(' JAVATPOINT ') AS SoundexString;

Output:

SoundexString
J131
1 row in set (0.00 sec)

Example 2:

In this example, we will Find the SOUNDEX string of 'WORLD' using the SOUNDEX Function in MySQL.

SELECT SOUNDEX('WORLD') AS SoundexString;

Output:

SoundexString
W643
1 row in set (0.00 sec)

Example 3:

When we require to find the SOUNDEX string for column data, then we can take the help of the SOUNDEX function in MySQL. For demonstration, we have created a table named Pupil.

CREATE TABLE Pupil(
Pupil_id INT AUTO_INCREMENT,
Pupil_name VARCHAR(100) NOT NULL,
Pupil_Class VARCHAR(20) NOT NULL,
PRIMARY KEY(Pupil_id )
);

Now we will insert some data into the Pupil table :

INSERT INTO Pupil
(Pupil_name, Pupil_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 Pupil Table is as follows.

mysql> select * from Pupil;
Pupil_idPupil_namePupil_Class
1Ananya MajumdarIX
2Anushka SamantaX
3Aniket SharmaXI
4Anik DasX
5Riya JainIX
6Tapan SamantaX
7Deepak SharmaX
8Ankana JanaXII
9Shreya GhoshX

Now, we are going to find the SOUNDEX string for column Pupil_name.

SELECT
Pupil_id, Pupil_name,
SOUNDEX( Pupil_name) AS SoundexSname,
Pupil_Class FROM Pupil ;

Output:

Pupil_idPupil_nameSoundexSnamePupil_Class
1Ananya MajumdarA52536IX
2Anushka SamantaA5253X
3Aniket SharmaA523265XI
4Anik DasA5232X
5Riya JainR250IX
6Tapan SamantaT15253X
7Deepak SharmaD1265X
8Ankana JanaA52525XII
9Shreya GhoshS620X

9 rows in set (0.00 sec)

Application of MySQL SOUNDEX() function:

This function is used to return a phonetic representation of a string.

Summary:

In the above context, we have learned how we can use the SOUNDEX() function in MySQL used to return a phonetic representation of a string.


Related Topics

MySQL REVERSE() function

In this context, we will learn how we can use the MySQL REVERSE() function with proper syntax and good examples. Introduction of MySQL REVERSE() function This function could be used to reverse...

2 minutes read.

MySQL CEILING() function

In this context, we will learn how we can use the MySQL CEILING () function with proper syntax and good examples. Introduction of MySQL CEILING () function The CEILING() function accepts the...

2 minutes read.

MySQL vs Oracle

What is MySQL? The open-source MySQL relational database management system is a vital software component for web-based applications. As the data is saved and sent over the internet, databases and related...

6 minutes read.

MySQL FORMAT() function

In this context, we will learn how we can use the MySQL FORMAT() function with proper syntax and good examples. Introduction of MySQL FORMAT() function This function in MySQL helps to format...

2 minutes read.

MySQL COALESCE function

This statement displays the first non-null value of the table data. The COALESCE function returns a null value when all values of the table are null or do not find...

3 minutes read.

MySQL DATE_ADD() function

In this context, we will learn how we can use the MySQL DATE_ADD() function with proper syntax and good examples. Introduction of MySQL DATE_ADD() function In MySQL, the DATE_ADD() function is used...

3 minutes read.

MySQL LEAST function

This statement displays the smallest value of the table. The LEAST function returns a null value when the table contains a null value. If the table contains all numerical values,...

2 minutes read.

MySQL LOAD_FILE() function

In this context, we will learn how we can use the MySQL LOAD_FILE() function with proper syntax and good examples. Introduction of MySQL LOAD_FILE() function The LOAD_FILE() function in MySQL reads a...

3 minutes read.

MySQL LOG2() function

In this context, we will learn how we can use the MySQL LOG2() function to calculate the Logarithm of a specific number with base 2 with proper syntax and examples. Introduction...

2 minutes read.

MySQL DELETE JOIN

Sometimes join becomes complicated and unwanted. In such cases, we can delete the unwanted joins in the tables. You can delete inner join, left join, right join as per requirement....

3 minutes read.

MySQL CURRENT_DATE() Function

In this context, we will learn how we can use the MySQL CURRENT_DATE() function to get the current date, and we will see in the two formats, such as strings...

2 minutes read.

MySQL RADIANS() function

In this context, we will learn how we can use the MySQL RADIANS() function with proper syntax and good examples. Introduction of MySQL RADIANS() function RADIANS() function in MySQL is used to...

2 minutes read.

MySQL LOCATE() function

In this context, we will learn how we can use the MySQL LOCATE() function with proper syntax and good examples. Introduction of MySQL LOCATE() function LOCATE() function in MySQL is used for...

3 minutes read.

MySQL Math Function

The math function operates numerical values and displays required number data. The math function finds out sin, cos, tan values. Here, you find out the absolute value, reminder, and logarithmic...

6 minutes read.

MySQL SUM function

The SUM() function displays the total addition of the table values. It supports the arithmetic operation of the column values. This function does not return a null value. Here, the...

5 minutes read.

MySQL Database Introduction

MySQL - Database Introduction: The database plays an essential role in MySQL for storing and modifying the data. The database creates and keeps multiple tables. The database organizes and manipulates...

8 minutes read.

MySQL Table

Introduction MySQL table is an essential part of the system. MySQL table stores data using index, rows, and columns. It accesses data from the server quickly because of the table—this table...

22 minutes read.

MySQL Invisible Index

Invisible Index MySQL index decides an option to the availability of the index for the query optimizer. This index shows the visible and invisible options to displays the index column in...

3 minutes read.

MySQL Character Length Function

In this context, we will learn how we can use the MySQL CHARACTER_LENGTH() function with proper syntax and good examples. Introduction of MySQL CHARACTER_LENGTH() function CHARACTER_LENGTH() function in MySQL is used to...

2 minutes read.

MySQL RIGHT() Function

In this context, we will learn how we can use the MySQL RIGHT() Function with proper syntax and good examples. Introduction of MySQL RIGHT() function The RIGHT() function in MySQL is used...

3 minutes read.