user1403909
user1403909

Reputation:

Reverse of soundex in mysql

select SOUNDEX('ram')

WILL RETURN 'R500'

Is there a way to input 'R500' and return 'ram'

something like this

select reverse_of_SOUNDEX('R500')

RESULT
--------
ram

Upvotes: 1

Views: 1075

Answers (2)

paxdiablo
paxdiablo

Reputation: 881463

You have the same problem as you would have for trying to reverse any many-to-one mapping function.

While ram may be one word that gives you the soundex code r500, so do a large number of other words (ran, rim, run, rune, rain and so on, depending on which variant of soundex you're using).

So which word would you like to see displayed in that case?

One possibility, if you're after a list of words, would be to populate a table with a large number of words (from a dictionary somewhere) along with their soundex codes. The codes can be set, after insertion of the words, quite easily with:

update sxmap set sxcode = soundex(word)

and then you can simply do:

select word from sxmap where sxcode = 'R500'

or:

select word from sxmap where sxcode = soundex('ram')

Upvotes: 3

Mitch Wheat
Mitch Wheat

Reputation: 300559

A Soundex mapping is essentially a Hash code (i.e a many-to-one mapping).

As such it is not uniquely reversible.

There are several words that can soundex map to R500, you cannot tell which was the original before mapping.

Upvotes: 2

Related Questions