0

I have some very basic beginner SQL knowledge. I've come across SOUNDEX and LIKE and have tried to implement them in my code.

In my database, I have a names column that contains all available names for a person (first, second, third, etc).

So far it looks like this:

SELECT names, date_of_birth, information
FROM person_list as p
WHERE ((SOUNDEX(%s) = SOUNDEX(names)) OR (names LIKE CONCAT('%', %s, '%')))

This only works if the input is the full name. For example, say I had a field with 'John Smith', if I searched 'Jon Smyth', this would work fine.

However, if I wanted to only search 'Smyth', nothing would come up. And if there was a field containing 'John Thomas Smith' I wouldn't be able to search for 'Jon Smyth' and have that field come up.

How do I fuzzy search for a word or multiple words within a field? (I am also open to finding a solution using Python which I am more comfortable with!)

Thanks in advance!

Ali
  • 1
  • Fuzzy search is concept not an algorithm (as much as some languages have functions as such) thr best implementations of this have been trained by cloud providers which can index strings and in most cases use AI to solve this problem. Soundex is woefully inadequate for real world tasks like this. Id suggest, if this is for commercial purposes looking at google, azure ect – TheGeneral May 21 '22 at 11:19
  • Please tag your rdbms , there is usually a built in solution – Andrew Sayer May 21 '22 at 15:45
  • First of all you need to normalize your data for the task. In your case, you need to split phrases into words and store them separately – Alex Salauyou May 21 '22 at 16:02

0 Answers0