Languages
[Edit]
EN

MySQL - soundex usage example

5 points
Created by:
Teilsa
1165

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:

SELECT 
	SOUNDEX('Robert'),    -- R163
	SOUNDEX('Rupert'),    -- R163
	SOUNDEX('Rubin'),     -- R150
	SOUNDEX('Ashcraft'),  -- A2613 (not A226)
	SOUNDEX('Ashcroft'),  -- A2613 (not A226)
	SOUNDEX('Tymczak'),   -- T520  (not T522)
	SOUNDEX('Pfister'),   -- P236
	SOUNDEX('Honeyman');  -- H500  (not H555)

Warning: MySQL modifies Soundex algorithm a little to own way.

Output:

R163
R163
R150
A2613
A2613
T520
P236
H500

 

More complicated example

The below example shows how to group similar words/keywords with SOUNDEX().

With SOUNDEX()Without SOUNDEX()
SELECT COUNT(`id`) as `group_size`
FROM `keywords`
GROUP BY SOUNDEX(`keyword`)

Conclusion: groups are bigger
(SOUNDEX() used to transform keywords before equals operator was used).

Example output:

SELECT COUNT(`id`) as `group_size`
FROM `keywords`
GROUP BY `keyword`

Conclusion: groups are smaller
(equals operator used to compare keywords).

 

Example output:

 

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join