sql - Compare two String with MySQL -


I can not compare two strings in a SQL request so that I can recover the best match, its purpose is to Operator is the best zip code possible. For example, in France, we have an integer zip code, so I made a simple request:

  SELECT * to myTable by ORDER stomach (zip_code - 75000)  

This request first returns the data of Paris's closest data.

Unfortunatelly, the ZIP code is AB421RS in the United Kingdom, so my request can not do this: I see a difference 'function' in SQL Server:

but I use MySQL ..

Is there someone who has a good idea to move in a simple request?

PS: Levenshtein will not do this distance, because I actually wan't like to compare wire if they were numbers. ABCDEF should be close to AWXEZ compared to ZBDDEF.

OK, I must stop asking questions only after the answer !!

For the community, this is what I will do:

  select * abs from myTable order (ascii (substring (zip_code, 1,1) - esi (astrati) ('AAAAAA', 1,1))) ACC, ABS (ASCII (AZRoad, 2.11)) - ASI (AASAA (substring (zip_code, 3,1)) - ascii ( ASCI (Astrais ('AAAAA', ASCI (AAAAAA, 5,1)) ACC (AAAAAA, 5), ASCI (Substring (Zipcode, 4,1)), substring ('AAAAA', 3,1) ACC, ABS 1)  

Comments