Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query soundex() in mysql

Tags:

mysql

soundex

What is the proper structure for searching within MySql using soundex()? I know how to produce a soundex():

select soundex('str');

just not sure how to include this in my query.

like image 932
jimmytiler Avatar asked Apr 13 '15 04:04

jimmytiler


3 Answers

If you're searching for "lewis" against the name field of people table, you perform this query:

SELECT *
FROM people
WHERE soundex("lewis") = soundex(name);

example here

like image 94
pala_ Avatar answered Oct 08 '22 20:10

pala_


Obviously, soundex isn't designed for partials like this (e.g. SELECT SOUNDEX('house cleaning'), SOUNDEX('house'), which would not match), but if you would like to perform a nasty SOUNDEX LIKE, you could

SELECT * FROM tablename WHERE SOUNDEX(column) LIKE CONCAT(SOUNDEX('partial_string'), '%')

You could also do

SELECT * FROM tablename WHERE SOUNDEX(column) LIKE CONCAT(TRIM(TRAILING '0' FROM SOUNDEX('hows ')), '%')

This "kinda" works

like image 3
Luke Madhanga Avatar answered Oct 08 '22 21:10

Luke Madhanga


This should work

select * from table_name where soundex(column_name) = soundex('word');

This is a good place to read about these:http://www.postgresonline.com/journal/archives/158-Where-is-soundex-and-other-warm-and-fuzzy-string-things.html

like image 1
thedarkgriffen Avatar answered Oct 08 '22 21:10

thedarkgriffen