Skip to content

Instantly share code, notes, and snippets.

@dionimercado
Forked from lsauer/fuzzy-search.sql
Created August 29, 2020 23:18
Show Gist options
  • Save dionimercado/ec5482c10bc4669e980ad8e7793c9db3 to your computer and use it in GitHub Desktop.
Save dionimercado/ec5482c10bc4669e980ad8e7793c9db3 to your computer and use it in GitHub Desktop.
FullText fuzzy searching in SQL / MySQL
#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