<p>How do I find duplicate addresses in a database, or better stop people already when filling in the form ? I guess the earlier the better?</p>

<p>Is there any good way of abstracting street, postal code etc so that typos and simple attempts to get 2 registrations can be detected? like: </p>

<pre><code>Quellenstrasse 66/11 
Quellenstr. 66a-11
</code></pre>

<p>I'm talking German addresses...
Thanks!</p>

[{'answer_id': 37577, 'author': 'svrist', 'author_id': 86, 'author_profile': 'https://Stackoverflow.com/users/86', 'pm_score': 0, 'selected': False, 'text': '<p>Often you use constraints in a database to ensure data to be "unique" in the data-based sense.</p>\n\n<p>Regarding "isomorphisms" I think you are on your own, ie writing the code your self. If in the database you could use a trigger.</p>\n'}, {'answer_id': 37585, 'author': 'ConroyP', 'author_id': 2287, 'author_profile': 'https://Stackoverflow.com/users/2287', 'pm_score': 3, 'selected': False, 'text': '<p>The earlier you can stop people, the easier it\'ll be in the long run! </p>\n\n<p>Not being too familiar with your db schema or data entry form, I\'d suggest a route something like the following:</p>\n\n<ul>\n<li><p>have distinct fields in your db for each address "part", e.g. street, city, postal code, Länder, etc.</p></li>\n<li><p>have your data entry form broken down similarly, e.g. street, city, etc</p></li>\n</ul>\n\n<p>The reasoning behind the above is that each part will likely have it\'s own particular "rules" for checking slightly-changed addressed, ("Quellenstrasse"->"Quellenstr.", "66/11"->"66a-11" above) so your validation code can check if the values as presented for each field exist in their respective db field. If not, you can have a class that applies the transformation rules for each given field (e.g. "strasse" stemmed to "str") and checks again for duplicates.</p>\n\n<p>Obviously the above method has it\'s drawbacks:</p>\n\n<ul>\n<li><p>it can be slow, depending on your data set, leaving the user waiting</p></li>\n<li><p>users may try to get around it by putting address "Parts" in the wrong fields (appending post code to city, etc). \nbut from experience we\'ve found that introducing even simple checking like the above will prevent a large percentage of users from entering pre-existing addresses.</p></li>\n</ul>\n\n<p>Once you\'ve the basic checking in place, you can look at optimising the db accesses required, refining the rules, etc to meet your particular schema. You might also take a look at <a href="http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html#function_match" rel="noreferrer">MySQL\'s match() function</a> for working out similar text.</p>\n'}, {'answer_id': 37588, 'author': 'Espo', 'author_id': 2257, 'author_profile': 'https://Stackoverflow.com/users/2257', 'pm_score': 3, 'selected': False, 'text': '<p>You could use the <a href="http://code.google.com/apis/maps/documentation/services.html#Geocoding_Direct" rel="noreferrer">Google GeoCode API</a></p>\n\n<p>Wich in fact gives results for both of your examples, just tried it. That way you get structured results that you can save in your database. If the lookup fails, ask the user to write the address in another way.</p>\n'}, {'answer_id': 37622, 'author': 'urini', 'author_id': 373, 'author_profile': 'https://Stackoverflow.com/users/373', 'pm_score': 2, 'selected': False, 'text': '<p>Before you start searching for duplicate addresses in your database, you should first make sure you store the addresses in a standard format.</p>\n\n<p>Most countries have a standard way of formatting addresses, in the US it\'s the USPS CASS system: <a href="http://www.usps.com/ncsc/addressservices/certprograms/cass.htm" rel="nofollow noreferrer">http://www.usps.com/ncsc/addressservices/certprograms/cass.htm</a></p>\n\n<p>But most other countries have a similar service/standard. Try this site for more international formats:\n<a href="http://bitboost.com/ref/international-address-formats.html" rel="nofollow noreferrer">http://bitboost.com/ref/international-address-formats.html</a></p>\n\n<p>This not only helps in finding duplicates, but also saves you money when mailing you customers (the postal service charges less if the address is in a standard format).</p>\n\n<p>Depending on your application, in some cases you might want to store a "vanity" address record as well as the standard address record. This keeps your VIP customers happy. A "vanity" address might be something like:</p>\n\n<p>62 West Ninety First Street<br>\nApartment 4D<br>\nManhattan, New York, NY 10001  </p>\n\n<p>While the standard address might look like this:</p>\n\n<p>62 W 91ST ST APT 4D<br>\nNEW YORK NY 10024-1414</p>\n'}, {'answer_id': 37623, 'author': 'Jon Limjap', 'author_id': 372, 'author_profile': 'https://Stackoverflow.com/users/372', 'pm_score': 2, 'selected': False, 'text': '<p>One thing you might want to look at are <a href="http://en.wikipedia.org/wiki/Soundex" rel="nofollow noreferrer">Soundex</a> searches, which are quite useful for misspellings and contractions. </p>\n\n<p>This however is not an in-database validation so it may or may not be what you\'re looking for.</p>\n'}, {'answer_id': 37641, 'author': 'ConroyP', 'author_id': 2287, 'author_profile': 'https://Stackoverflow.com/users/2287', 'pm_score': 3, 'selected': True, 'text': '<blockquote>\n<p>Johannes:</p>\n<blockquote>\n<p>@PConroy: This was my initial thougt also. the interesting part on this is to find good transformation rules for the different parts of the address! Any good suggestions?</p>\n</blockquote>\n</blockquote>\n<p>When we were working on this type of project before, our approach was to take our existing corpus of addresses (150k or so), then apply the most common transformations for our domain (Ireland, so &quot;Dr&quot;-&gt;&quot;Drive&quot;, &quot;Rd&quot;-&gt;&quot;Road&quot;, etc). I\'m afraid there was no comprehensive online resource for such things at the time, so we ended up basically coming up with a list ourselves, checking things like the phone book (pressed for space there, addresses are abbreviated in all manner of ways!). As I mentioned earlier, you\'d be amazed how many &quot;duplicates&quot; you\'ll detect with the addition of only a few common rules!</p>\n<p>I\'ve recently stumbled across a page with a fairly comprehensive <a href="https://sites.google.com/site/masteraddressfile//zp4/abbrev" rel="nofollow noreferrer">list of address abbreviations</a>, although it\'s american english, so I\'m not sure how useful it\'d be in Germany! A quick google turned up a couple of sites, but they seemed like spammy newsletter sign-up traps. Although that was me googling in english, so you may have more look with &quot;german address abbreviations&quot; in german :)</p>\n'}, {'answer_id': 37654, 'author': 'Johannes', 'author_id': 925, 'author_profile': 'https://Stackoverflow.com/users/925', 'pm_score': 1, 'selected': False, 'text': '<p>To add an answer to my own question: </p>\n\n<p>A different way of doing it is ask users for their mobile phone number, send them a text msg for verification. This stops most people messing with duplicate addresses.</p>\n\n<p>I\'m talking from personal experience. (thanks <a href="http://www.pigsback.ie" rel="nofollow noreferrer">pigsback</a> !) They introduced confirmation through mobile phone. That stopped me having 2 accounts! :-)</p>\n'}, {'answer_id': 39043, 'author': 'mdy', 'author_id': 480, 'author_profile': 'https://Stackoverflow.com/users/480', 'pm_score': 2, 'selected': False, 'text': '<p>Another possible solution (assuming you actually need reliable address data and you\'re not just using addresses as a way to prevent duplicate accounts) is to use a third-party web service to standardize the addresses provided by your users. </p>\n\n<p>It works this way -- your system accepts a user\'s address via an online form. Your form hands off the user\'s address to the third-party address standardization web service. The web service gives you back the same address but now with the data standardized into discrete address fields, and with the standard abbreviations and formats applied. Your application displays this standardized address to your user for their confirmation before attempting to save the data in your DB.</p>\n\n<p>If all the user addresses go through a standardization step and only standardized addresses are saved to your DB, then finding duplicate records should be greatly simplified since you are now comparing apples to apples.</p>\n\n<p>One such third-party service is <a href="http://www.globaladdress.net/?pn=globaladdressinteractive" rel="nofollow noreferrer">Global Address\'s Interactive Service</a> which includes Germany in the list of supported countries, and also has an online demo that demonstrates how their service works (demo link can be found on that web page).</p>\n\n<p>There\'s a cost disadvantage to this approach, obviously. However, on the plus side:</p>\n\n<ol>\n<li>you would not need to create and maintain your own address standardization metadata</li>\n<li>you won\'t need to continuously enhance your address standardization routines, and</li>\n<li>you\'re free to focus your software development energy on the parts of the application that are unique to your requirements </li>\n</ol>\n\n<p>Disclaimer: I don\'t work for Global Address and have not tried using their service. I\'m merely mentioning them as an example since they have an online demo that you can actually play with.</p>\n'}, {'answer_id': 7748550, 'author': 'Jonathan Oliver', 'author_id': 151741, 'author_profile': 'https://Stackoverflow.com/users/151741', 'pm_score': 2, 'selected': False, 'text': '<p>I realize that the original post is specif to German addresses, but this is a good questions for addresses in general.</p>\n<p>In the United States, there is a part of an address called a delivery point barcode.  It\'s a unique 12-digit number that identifies a single point of delivery and can serve as the unique identifier of an address.  To get this value you\'ll want to use an address verification or address standardization web service API, which can cost about $20/mo depending upon the volume of requests you make to it.</p>\n<p>In the interest of full disclosure, I\'m the founder of SmartyStreets.  We offer just such an <a href="http://www.smartystreets.com/Products/LiveAddress-API/" rel="nofollow noreferrer">address validation web service API</a> called LiveAddress.  You\'re more than welcome to contact me personally with any questions you have.</p>\n'}, {'answer_id': 44895045, 'author': 'A STEFANI', 'author_id': 4471715, 'author_profile': 'https://Stackoverflow.com/users/4471715', 'pm_score': -1, 'selected': False, 'text': '<p>In my opinion, assuming that you already had a lot of dirty data in your DB, </p>\n\n<p>You have to do build your "handmade" dirty filter which may detect a maximum of german abreviation ... </p>\n\n<p>But If you treat a lot of data, you will take the risk to find some false-positive and true-negative sample...</p>\n\n<p>Finally a semi automated job (machine with human assist when probability of a case of false-positive or true-negative is too high) will be the best solution.</p>\n\n<p>More you treat "exception" (because human raise exception when filling data), more your "handmade" filter will fit your requierement.</p>\n\n<p>In the other hand, you may also use a germany address verification service on user side, and store only the verified one...</p>\n'}, {'answer_id': 44897826, 'author': 'Sagar V', 'author_id': 2427065, 'author_profile': 'https://Stackoverflow.com/users/2427065', 'pm_score': 0, 'selected': False, 'text': '<blockquote>\n<p>I\'m looking for an answer addressing United States addresses</p>\n</blockquote>\n<p>The issue in question is prevent users from entering duplicates like</p>\n<blockquote>\n<p><code>Quellenstrasse 66/11</code> and\n<code>Quellenstr. 66a-11</code></p>\n</blockquote>\n<p>This happens when you let your user enter the complete address in input box.</p>\n<p>There are some methods you can use to prevent this.</p>\n<h1>1. Uniform formatting using RegEx</h1>\n<ul>\n<li>You can prompt users to enter the details in a uniform format.</li>\n<li>That is very efficient while querying too</li>\n<li>test the user entered value against some regular expressions and if failed, ask user to correct it.</li>\n</ul>\n<h1>2.Use a map api like google maps and ask the user to select details from it.</h1>\n<ul>\n<li>If you choose google maps, you can achieve it using Reverse Geocoding.</li>\n</ul>\n<p>From <a href="https://developers.google.com/maps/documentation/geocoding/intro#ReverseGeocoding" rel="nofollow noreferrer">Google Developer\'s guide</a>,</p>\n<blockquote>\n<p>The term geocoding generally refers to translating a human-readable address into a location on a map. <strong>The process of doing the opposite, translating a location on the map into a human-readable address, is known as <em>reverse geocoding</em>.</strong></p>\n</blockquote>\n<h1>3. Allow heterogeneous data as shown in the question and compare it with different formatting.</h1>\n<ul>\n<li>In the question, the OP allow address in different format.</li>\n<li>In such case, you can change it to different forms and check it with database to get a solution.</li>\n<li>This may take more time and the time is completely depends on the number of test cases.</li>\n</ul>\n<h1>4. Split the address into different parts and store it in db and provide such a form to user.</h1>\n<ul>\n<li>That is provide different fields to store Street, city, state etc in database.</li>\n<li>Also provide the different input fields to user to enter street, city, state, etc in top down format.</li>\n<li>When user enter state, narrow the query to find dupes to that state only.</li>\n<li>When user enter city, narrow it to that city only.</li>\n<li>When user enter the street, narrow it to that street.</li>\n</ul>\n<p>And finally</p>\n<ul>\n<li>When user enter the address, change it to different formats and test it against Data Base.</li>\n</ul>\n<blockquote>\n<p>This is efficient even the number of test cases may high, the number of entries you test against will be very less and so it will consume very less amount of time.</p>\n</blockquote>\n'}, {'answer_id': 44913924, 'author': 'Tal Avissar', 'author_id': 2663692, 'author_profile': 'https://Stackoverflow.com/users/2663692', 'pm_score': 1, 'selected': False, 'text': '<p>Machine learning and AI has algorithms to find string similarities and duplicate measures.</p>\n\n<p>Record linkage or the task of matching equivalent records\nthat differ syntactically—was first explored in the late 1950s\nand 1960s.</p>\n\n<p>You can represent every pair of records using a vector of\nfeatures that describe the similarity between individual record fields. </p>\n\n<p>For example, Adaptive Duplicate Detection Using Learnable String\nSimilarity Measures. for example, <a href="http://www.cs.utexas.edu/~ml/papers/marlin-kdd-03.pdf" rel="nofollow noreferrer">read this doc</a></p>\n\n<ol>\n<li><p>You can use generic or manually tuned distance metrics for estimating the similarity of potential duplicates.</p></li>\n<li><p>You can use adaptive name matching algorithms, like Jaro metric, which is based on the number and order of common characters between two strings.</p></li>\n<li><p>Token-based and hybrid distance. In such cases, we can convert the\nstrings s and t to token multisets (where each token is a word) and consider similarity metrics on these multisets.</p></li>\n</ol>\n'}, {'answer_id': 44935403, 'author': 'kichik', 'author_id': 492773, 'author_profile': 'https://Stackoverflow.com/users/492773', 'pm_score': 0, 'selected': False, 'text': '<p>In the USA, you can use USPS <a href="https://www.usps.com/business/web-tools-apis/address-information-api.htm" rel="nofollow noreferrer">Address Standardization Web Tool</a>. It verifies and normalizes addresses for you. This way, you can normalize the address before checking if it already exists in the database. If all the addresses in the database are already normalized, you\'ll be able to spot duplicates easily.</p>\n\n<p>Sample URL:</p>\n\n<p><a href="https://production.shippingapis.com/ShippingAPI.dll?API=Verify&amp;XML=insert_request_XML_here" rel="nofollow noreferrer">https://production.shippingapis.com/ShippingAPI.dll?API=Verify&amp;XML=insert_request_XML_here</a></p>\n\n<p>Sample request:</p>\n\n<pre><code>&lt;AddressValidateRequest USERID="XXXXX"&gt;\n  &lt;IncludeOptionalElements&gt;true&lt;/IncludeOptionalElements&gt;\n  &lt;ReturnCarrierRoute&gt;true&lt;/ReturnCarrierRoute&gt;\n  &lt;Address ID="0"&gt;  \n    &lt;FirmName /&gt;   \n    &lt;Address1 /&gt;   \n    &lt;Address2&gt;205 bagwell ave&lt;/Address2&gt;   \n    &lt;City&gt;nutter fort&lt;/City&gt;   \n    &lt;State&gt;wv&lt;/State&gt;   \n    &lt;Zip5&gt;&lt;/Zip5&gt;   \n    &lt;Zip4&gt;&lt;/Zip4&gt; \n  &lt;/Address&gt;      \n&lt;/AddressValidateRequest&gt;\n</code></pre>\n\n<p>Sample response:</p>\n\n<pre><code>&lt;AddressValidateResponse&gt;\n  &lt;Address ID="0"&gt;\n    &lt;Address2&gt;205 BAGWELL AVE&lt;/Address2&gt;\n    &lt;City&gt;NUTTER FORT&lt;/City&gt;\n    &lt;State&gt;WV&lt;/State&gt;\n    &lt;Zip5&gt;26301&lt;/Zip5&gt;\n    &lt;Zip4&gt;4322&lt;/Zip4&gt;\n    &lt;DeliveryPoint&gt;05&lt;/DeliveryPoint&gt;\n    &lt;CarrierRoute&gt;C025&lt;/CarrierRoute&gt;\n  &lt;/Address&gt;\n&lt;/AddressValidateResponse&gt;\n</code></pre>\n\n<p>Other countries might have their own APIs. Other people mentioned 3rd party APIs that support multiple countries that might be useful in some cases.</p>\n'}, {'answer_id': 44986716, 'author': 'Muhammad Muazzam', 'author_id': 2456918, 'author_profile': 'https://Stackoverflow.com/users/2456918', 'pm_score': 0, 'selected': False, 'text': '<p>As google fetch suggesions for search you can search database address fields </p>\n\n<p>First, let’s create an index.htm(l) file:</p>\n\n<pre><code>    &lt;!DOCTYPE html&gt;\n    &lt;html lang="en"&gt;\n\n    &lt;head&gt;\n        &lt;meta http-equiv="Content-Language" content="en-us"&gt;\n        &lt;title&gt;Address Autocomplete&lt;/title&gt;\n        &lt;meta charset="utf-8"&gt;\n        &lt;link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"&gt;\n        &lt;script src="//code.jquery.com/jquery-2.1.4.min.js"&gt;&lt;/script&gt;\n        &lt;script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"&gt;&lt;/script&gt;\n        &lt;script src="//netsh.pp.ua/upwork-demo/1/js/typeahead.js"&gt;&lt;/script&gt;\n        &lt;style&gt;\n            h1 {\n                font-size: 20px;\n                color: #111;\n            }\n\n            .content {\n                width: 80%;\n                margin: 0 auto;\n                margin-top: 50px;\n            }\n\n            .tt-hint,\n            .city {\n                border: 2px solid #CCCCCC;\n                border-radius: 8px 8px 8px 8px;\n                font-size: 24px;\n                height: 45px;\n                line-height: 30px;\n                outline: medium none;\n                padding: 8px 12px;\n                width: 400px;\n            }\n\n            .tt-dropdown-menu {\n                width: 400px;\n                margin-top: 5px;\n                padding: 8px 12px;\n                background-color: #fff;\n                border: 1px solid #ccc;\n                border: 1px solid rgba(0, 0, 0, 0.2);\n                border-radius: 8px 8px 8px 8px;\n                font-size: 18px;\n                color: #111;\n                background-color: #F1F1F1;\n            }\n        &lt;/style&gt;\n        &lt;script&gt;\n            $(document).ready(function() {\n\n                $(\'input.city\').typeahead({\n                    name: \'city\',\n                    remote: \'city.php?query=%QUERY\'\n\n                });\n\n            })\n        &lt;/script&gt;\n\n    &lt;script&gt;\n            function register_address()\n            {\n                $.ajax({\n                    type: "POST",\n                    data: {\n                        City: $(\'#city\').val(),\n                    },\n                    url: "addressexists.php",\n                    success: function(data)\n                    {\n                        if(data === \'ADDRESS_EXISTS\')\n                        {\n                            $(\'#address\')\n                                .css(\'color\', \'red\')\n                                .html("This address already exists!");\n                        }\n\n                    }\n                })              \n            }\n        &lt;/script&gt;\n    &lt;/head&gt;\n\n    &lt;body&gt;\n        &lt;div class="content"&gt;\n\n            &lt;form&gt;\n                &lt;h1&gt;Try it yourself&lt;/h1&gt;\n                &lt;input type="text" name="city" size="30" id="city" class="city" placeholder="Please Enter City or ZIP code"&gt;\n&lt;span id="address"&gt;&lt;/span&gt;\n            &lt;/form&gt;\n        &lt;/div&gt;\n    &lt;/body&gt;\n&lt;/html&gt;\n</code></pre>\n\n<p>Now we will create a city.php file which will aggregate our query to MySQL DB and give response as JSON. Here is the code:</p>\n\n<pre><code>&lt;?php\n\n//CREDENTIALS FOR DB\ndefine (\'DBSERVER\', \'localhost\');\ndefine (\'DBUSER\', \'user\');\ndefine (\'DBPASS\',\'password\');\ndefine (\'DBNAME\',\'dbname\');\n\n//LET\'S INITIATE CONNECT TO DB\n$connection = mysqli_connect(DBSERVER, DBUSER, DBPASS,"DBNAME") or die("Can\'t connect to server. Please check credentials and try again");\n\n\n//CREATE QUERY TO DB AND PUT RECEIVED DATA INTO ASSOCIATIVE ARRAY\nif (isset($_REQUEST[\'query\'])) {\n    $query = $_REQUEST[\'query\'];\n    $sql = mysqli_query ($connection ,"SELECT zip, city FROM zips WHERE city LIKE \'%{$query}%\' OR zip LIKE \'%{$query}%\'");\n    $array = array();\n    while ($row = mysqli_fetch_array($sql,MYSQLI_NUM)) {\n        $array[] = array (\n            \'label\' =&gt; $row[\'city\'].\', \'.$row[\'zip\'],\n            \'value\' =&gt; $row[\'city\'],\n        );\n    }\n    //RETURN JSON ARRAY\n    echo json_encode ($array);\n}\n\n?&gt;\n</code></pre>\n\n<p>and then prevent saving them into database if found duplicate in table column </p>\n\n<p>And for your addressexists.php code:</p>\n\n<pre><code>&lt;?php//CREDENTIALS FOR DB\n    define (\'DBSERVER\', \'localhost\');\n    define (\'DBUSER\', \'user\');\n    define (\'DBPASS\',\'password\');\n    define (\'DBNAME\',\'dbname\');\n\n    //LET\'S INITIATE CONNECT TO DB\n    $connection = mysqli_connect(DBSERVER, DBUSER, DBPASS,"DBNAME") or die("Can\'t connect to server. Please check credentials and try again");\n\n\n    $city= mysqli_real_escape_string($_POST[\'city\']); // $_POST is an array (not a function)\n    // mysqli_real_escape_string is to prevent sql injection\n\n    $sql = "SELECT username FROM ".TABLENAME." WHERE city=\'".$city."\'"; // City must enclosed in two quotations\n\n    $query = mysqli_query($connection,$sql);\n\n    if(mysqli_num_rows($query) != 0)\n\n    {\n        echo(\'ADDRESS_EXISTS\');\n    }\n?&gt;\n</code></pre>\n'}, {'answer_id': 45014373, 'author': 'danny117', 'author_id': 2202675, 'author_profile': 'https://Stackoverflow.com/users/2202675', 'pm_score': 0, 'selected': False, 'text': '<p>Match address to addresses provided by DET BundesPost to detect duplicates.</p>\n\n<p>DET probably sells a CD like USA does.  The problem then becomes matching to the Bundespost addresses.  Just a long process of replacing abbreviations with the post approved abbreviations and such.</p>\n\n<p>Same way in USA. Match to USPostOffice addresses (Sorry these cost money so its not entirely open CDs are available from the US post office) to find duplicates.</p>\n'}]
['https://Stackoverflow.com/questions/37568', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/925/']