×

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 POW() function

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

2 minutes read.

MySQL Prefix index

Prefix index This index query creates an index column in the string or character column. MySQL system can create multiple indexes in the table. It will create in a table as...

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 Date and Time function

The date function displays day, year, month, time, and current date. It shows the date and time as per the requirement of the applications. The data either store on the...

8 minutes read.

MySQL COUNT function

The count function returns the number of rows in the table. This function shows either the entire rows count or the required row count of the table. It determines the...

5 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 Environmental Setup

The MySQL Environmental Setup MySQL is free, open-source, and cross-platform software, which can be downloaded from its official website. MySQL management system installs on Linux, macOS, and windows. MySQL requires a framework...

6 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 function

MySQL function is a piece of program to perform some specific task. Here we pass a parameter and then return a single value. MySQL function mainly supports string, numeric, conditional,...

9 minutes read.

MySQL Triggers

MySQL trigger is a function of the stored procedure to respond to the system program. This function responds and runs any data table event automatically. You can use it for...

5 minutes read.

MySQL RIGHT JOIN

MySQL right join links two tables with each other. The left table column connects with the complete right side table. Each row of the right table tries to connect with...

4 minutes read.

MySQL String Function

The string function is used to maintain and operate string values. This function modifies the string data as per function. We can do the concatenation, conversion, removal and replacing the...

4 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.

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 Descending Index

Descending Index It is a type of index that stores key values in descending order. This query improves the performance of an index query. MySQL system displays the index as per...

3 minutes read.

MySQL Features

Features of MySQL MySQL is a relational database management system (RDBMS): It is a collection of many programs and makes relations with many other programs. Easy to use MySQL database: MySQL...

2 minutes read.

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 Clauses

MySQL Clauses MySQL system clauses are keywords or statements to handle information. It helps to operate a group of the data and apply it to require conditions. The clauses apply conditions...

16 minutes read.

MySQL CROSS JOIN

MySQL CROSS JOIN combines all possibilities of the two or more tables and returns the result that contains every row from all contributing tables. It links several columns from the...

4 minutes read.

MySQL ELT() function

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

2 minutes read.