Skip to content

Instantly share code, notes, and snippets.

@jlcarvalho
Forked from lsauer/fuzzy-search.sql
Last active February 6, 2020 00:27
Show Gist options
  • Save jlcarvalho/a2338323304fb80866df to your computer and use it in GitHub Desktop.
Save jlcarvalho/a2338323304fb80866df to your computer and use it in GitHub Desktop.
#lo sauer, 2013 - www.lsauer.com
#see: http://www.lsauer.com/2013/05/mysql-fuzzy-searching-fulltext-queries.html
#Note: In MySQL SUBSTRING, the string-index starts at position 1
SELECT * FROM tablename
WHERE SOUNDEX(tablename_field)
LIKE CONCAT('%',SUBSTRING(SOUNDEX('Fuzti serch derm'),2),'%');
SELECT SUBSTRING("fb stands for foobar",1);
#"fb stands for foobar"
SELECT SOUNDEX("fb");
#F000
SELECT SOUNDEX("fbs");
#F200
SELECT SOUNDEX("stands");
#S3532
SELECT SOUNDEX("for");
#F600
SELECT SOUNDEX("foobar");
#F600
SELECT SOUNDEX("for foobar");
#F616
SELECT SOUNDEX("sfor foobar");
#F1616
SELECT SOUNDEX("fb stands for foobar");
#F2 3532 1616; spaces are for clarity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment