Data Loader

MS SQL Server SOUNDEX function and it's equivalent in MySQL

The SOUNDEX function is used for checking whether two words are pronounced same irrespective of how they are spelled.

For example if a person is having "Smith" name. Some people spelled it as "Smith" and some people write it as "Smythe". However they are spelled they are pronounced same.

MS SQL Server

Syntax

SOUNDEX ( character_expression )  

Example

Suppose we have a table column "LastName" and in this column there are various employees whose lastname is Smith but they have written it differently. To find out all those rows whose names are pronounced as Smith, you can use SOUNDEX function.

Example Employees table

select * from employees where SOUNDEX(lastname)=SOUNDEX('smith');

 Soundex Function Example in MSSQL

SOUNDEX converts an alphanumeric string to a four-character code that is based on how the string sounds when spoken.

If you just give the following query it will show the four character code for string

 

MySQL

SOUNDEX function is also available in MySQL. But it works only for English language and words of other languages are not supported as of MySQL version 5.1

Syntax

SOUNDEX(str)

Example

Suppose in MySQL we have table by name 'Employees' with the following data

MySQL Example Table

 

Now to see all the employees whose name sounds like 'Smith' you can use the SOUNDEX function like this

select * from employees where SOUNDEX(lastname)=SOUNDEX('smith') 

SOUNDEX example in mysql

In MySQL you instead of the above query you can also give the following query which will produce the same result

select * from employees where lastname SOUNDS LIKE 'smith'
i.e. instead of writing SOUNDEX(lastname)=SOUNDEX('smith') you can write the query in
 simple english lastname SOUNDS LIKE 'smith'

 

Back to Converting Functions from MSSQL to MySQL