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.
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.
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);
soundex("lewis") = L200
and soundex("luis") = L200
. So soundex("lewis") = soundex("luis")
matches, whereas "lewis" = "luis"
obviously would not. Words that "sound the same" in english should usually have the same code. –
Prendergast 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
MySQL has a native way of doing this now!
You can use the syntax SOUNDS LIKE
to do a similarity search.
SELECT * FROM table Where SOUNDEX(`field1`) = SOUNDEX(`field2`);
Is equivalent to:
SELECT * FROM table Where `field1` SOUNDS LIKE `field2`;
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
© 2022 - 2024 — McMap. All rights reserved.
where soundex("search_string") = soundex(search_column)
– Prendergast