EN
MySQL - soundex usage example
5 points
In this short article, we would like to show how to use Soundex algorithm in MySQL.
Soundex is implemented by default in MySQL by SOUNDEX()
function.
Practical example:
xxxxxxxxxx
1
SELECT
2
SOUNDEX('Robert'), -- R163
3
SOUNDEX('Rupert'), -- R163
4
SOUNDEX('Rubin'), -- R150
5
SOUNDEX('Ashcraft'), -- A2613 (not A226)
6
SOUNDEX('Ashcroft'), -- A2613 (not A226)
7
SOUNDEX('Tymczak'), -- T520 (not T522)
8
SOUNDEX('Pfister'), -- P236
9
SOUNDEX('Honeyman'); -- H500 (not H555)
Warning: MySQL modifies Soundex algorithm a little to own way.
Output:
xxxxxxxxxx
1
R163
2
R163
3
R150
4
A2613
5
A2613
6
T520
7
P236
8
H500
The below example shows how to group similar words/keywords with SOUNDEX()
.
With SOUNDEX() | Without SOUNDEX() |
xxxxxxxxxx 1 SELECT COUNT(`id`) as `group_size` 2 FROM `keywords` 3 GROUP BY SOUNDEX(`keyword`)
Example output: |
xxxxxxxxxx 1 SELECT COUNT(`id`) as `group_size` 2 FROM `keywords` 3 GROUP BY `keyword`
Example output: |