mysql - How select a akin records?
I have a table with
name varchar
address varchar
country varchar
city varchar
.....
to store address of location
example:
开发者_JAVA技巧name|address|country
HaLong hotel|156 blahblah street|Vietnam
Hotel Ha Long|156 blah blah|Vietnam
Two rows above is duplicate data.
I have a form, when user submit new location. The code need to find akin records to give a message (ex: This location already in db, use it or create new?)
How to make a query to get akin record like this?
"156 blahblah street" and "156 blah blah" don't have enough in common to automate anything from without a lot of work, and it won't be happening in a single SQL query.
3 options to try:
1) Use something like Google Maps' Geocoding to look up the address, it's pretty good at figuring out that people mean "avenue" when they type "street" & other common mistakes, so most typos can be avoided. Also you can get longitude/latitude data to make sure it matches.
2) Use an autocompleter on the address text fields. When someone types "156 blah," it will bring up a list of everything that matches so users will be more likely to pick the right one.
3) Implement your own language algorithms using soundex, etc., that will probably be terribly slow compared to Geocoding. I'd avoid this option - sounds fun but it's way too impractical.
Before inserting the data into database . you select rows from the table with current data's . If the select query returns number of rows, which is not grater than zero So, you can sure that , the information already exist, otherwise you can do the further thing.
.
精彩评论