How would the best way to approach this problem be?

  • Search for user by first name, where the parameter is a string. The result should display a list of the 10 users whose first name is closest to the searched string.

Clearly there are different ways to approach this one. Is there any mysql functionality that does this already?

Should I just query all my rows and run some kind of search function?

share|improve this question
what does "closest to" mean? – hackattack Aug 1 '12 at 22:21
visually similar. – James Andino Aug 1 '12 at 22:22
Are you using InnoDB or MyISAM engine for the table? How many users do you plan on having in the DB? – drew010 Aug 1 '12 at 22:23
1  
You could use the SOUNDEX function of MySQL if you mean "sounds close enough". – tadman Aug 1 '12 at 22:26
10, 000 it is just a test query I have to write. No worry about efficiency on this one. – James Andino Aug 1 '12 at 22:37
show 1 more comment
feedback

1 Answer

Have a look at MySQL Full-Text search functions which will automatically return results based on relevancy, though it will not work with InnoDB.

share|improve this answer
There is a pretty big drawback to using MySQL Full-Text searches: you cannot search for substrings (just for prefixes). – apfelbox Aug 1 '12 at 23:46
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.