I have a table with alternative spellings of country names:
Use name, Alt1, Alt2, Alt3, Alt4
[...]
Bahamas, "Bahamas, The"
Bolivia
Bosnia and Herzegovina, Bosnia & Herzegovina
[...]
(Some countries have 0 alternative spellings, other up to 4.)
Given a country string, what is performance-wise the best solution to returning the element in the first column? (In most of the cases, independent of the number of alternative spellings, the string matches the first column and doesn't have to be name-matched. In the other cases the probability is evenly distributed across column 2-X.
(Preferably in JavaScript or PHP, thanks :) )
In my opinion, I think you should put this in two separate tables in database:
Put an index on the name column so that you can search fast for the correct name and country_id:
(optionally, you can add a
LEFT JOIN
if you need more info from the main table)Other option would be to create a table only for alternative names:
But you'd have to search in two tables when looking for a first match.
EDIT: Static JavaScript solution: