MySQL SOUNDEX() Function

In MySQL, the SOUNDEX() function returns a soundex string representing the pronunciation of the string. The SOUNDEX() function is used to compare whether the pronunciation of two words is the same. If two words are pronounced the same, their soundex strings are the same.

SOUNDEX() Syntax

Here is the syntax of MySQL SOUNDEX() function:

SOUNDEX(string)

Parameters

string
Required. A word that you want to return the soundex string.

Return value

The SOUNDEX(string) function returns a soundex string representing the pronunciation of the string.

Standard soundex strings are four characters, but the SOUNDEX() function may return strings longer than four. If you want to get a standard soundex string, you can use the SUBSTRING() function to truncate the result of the SOUNDEX() function.

The SOUNDEX(string) function only handles alphabetic letters, other non-alphabetic characters are ignored.

SOUNDEX() Examples

Let’s see a few SOUNDEX() examples :

SELECT
    SOUNDEX('HelloWorld'),
    SOUNDEX('World')\G
SOUNDEX('Hello'): H400
SOUNDEX('World'): W643

Let’s see a few words with the same soundex:

SELECT
    SOUNDEX('Dam'),
    SOUNDEX('Damn'),
    SOUNDEX('Too'),
    SOUNDEX('Two'),
    SOUNDEX('Color'),
    SOUNDEX('Colour')\G
   SOUNDEX('Dam'): D500
  SOUNDEX('Damn'): D500
   SOUNDEX('Too'): T000
   SOUNDEX('Two'): T000
 SOUNDEX('Color'): C460
SOUNDEX('Colour'): C460

Although some words are pronounced the same, they have different soundex strings if they start with different letters.

SELECT
    SOUNDEX('Hole'),
    SOUNDEX('Whole'),
    SOUNDEX('Our'),
    SOUNDEX('Hour')\G
 SOUNDEX('Hole'): H400
SOUNDEX('Whole'): W400
  SOUNDEX('Our'): O600
 SOUNDEX('Hour'): H600