Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have to use the soundex() function with LIKE %...% in Mysql. I don't have the idea how should I write the query. I have made the query like this.

$query = "SELECT * FROM tbl_name WHERE soundex(fieldname) LIKE soundex(%'element'%)";


but it is not working.

Can Some one Help me?
Posted
Updated 20-Jun-17 20:36pm

You cannot not use SOUNDEX[^] like that. But you can do

SQL
SELECT * FROM tbl_name WHERE fieldname SOUNDS LIKE 'element'
 
Share this answer
 
Comments
rashidfarooq 24-May-11 12:20pm    
if I use this query there is problem in it.
Suppose user enters "day of the week" as the value for element. But in the database the field value is "week day". Then this query will miss this value. using LIKE %..% this value could not be missed. But if I use only LIKE %...% then I can not handle the spelling mistakes. So, Is there any other solution for my problem?
Kim Togo 24-May-11 15:47pm    
Yes I can see the problem. In fact I have the same problem. But for the must it is a single word.
Perhaps this can help ?
http://www.imranulhoque.com/mysql/mysql-function-soundex-match-multi-word-string/
rashidfarooq 24-May-11 22:54pm    
thanks for reply. This function is good. But this function can not be used to search equally sounds values from mysql database. We need a proper sql query to do that. Any other Idea?
Kim Togo 25-May-11 4:14am    
I long time a go, I found this PDF file.
http://nlp.stanford.edu/IR-book/pdf/irbookonlinereading.pdf

Try look at page 43 - 3. Dictionaries and tolerant retrieval
You can use the following :

$query = "SELECT * FROM tbl_name WHERE soundex(fieldname) LIKE soundex('%element%')";

Or

$query = "SELECT * FROM tbl_name WHERE soundex(fieldname) LIKE soundex('element')";

Or

$query = "SELECT * FROM tbl_name WHERE fieldname SOUNDS LIKE '%element%'";

Or

$query = "SELECT * FROM tbl_name WHERE fieldname SOUNDS LIKE 'element'";
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900