Compare two String with MySQL
Posted
by Scorpi0
on Stack Overflow
See other posts from Stack Overflow
or by Scorpi0
Published on 2010-06-18T15:36:45Z
Indexed on
2010/06/18
15:53 UTC
Read the original article
Hit count: 423
Hi,
I wan't to compare two strings in a SQL request so I can retrieve the best match, the aim is to propose to an operator the best zip code possible. For example, in France, we have Integer Zip code, so I made an easy request :
SELECT *
FROM myTable
ORDER BY abs(zip_code - 75000)
This request returns first the data closest of Paris.
Unfortunatelly, United Kingdom have zip code like AB421RS, so my request can't do it. I see in SQL Server a function 'Difference' : http://www.java2s.com/Code/SQLServer/String-Functions/DIFFERENCEworkoutwhenonestringsoundssimilartoanotherstring.htm
But I use MySQL..
Is there anyone who have a good idea to do the trick in one simple request ?
PS : the Levenshtein Distance will not do it, as I really wan't to compare string like if they were number. ABCDEF have to be closer to AWXYZ than to ZBCDEF.
© Stack Overflow or respective owner