Ok this is going to get a bit chaotic so please try to stay with me..
I got a table of information kind of like this…
Table Name: Customers
_____________________________
ID | CompanyName | FirstName | LastName | Phone
-------------------------------
1 | Joes | Joe | James | 1233334444
2 | Kennys | Kenny | Johnson | 2222334555
3 | Kellys | Kelly | Gibson | 5454445445
4 | Ricks #1 | Rick | Lawson | 4545334222
5 | Johns #1 | Johny B | James | 4545222211
6 | Johns #2 | Johny | James | 4545222211
7 | Johns #3 | Johny | James | 4545222211
8 | Ricks #2 | Rick A | Lawson | 4545334222
I need to know how to create an SQL statement that finds all the duplicate records, adds them up, then displays the total amount of duplicates found with the first company name found.
*HERE’s THE CATCH – As you see from the table above, sometimes they put their initials with their name (Example – ID5 and ID6 are the same exact person, but he put his middle initial in ID5, you can see the same with ID4 and ID7)
I need the SQL statement to base the comparison off first matching the lastname, then doing a “IS LIKE” on the first name and company name “kind-of-thing” to make sure that they are being counted as they should be.
For Example – I should get a result similar to…
Table Name: TableResults
_____________________________
ID | CompanyName | FirstName | LastName | Phone | Count
-------------------------------
4 | Ricks #1 | Rick | Lawson | 4545334222 | 2
5 | Johns #1 | Johny B | James | 4545222211 | 3
Is this even possible?
I think you might need to use fuzzy matching.
Try this:
SQLFiddle: http://sqlfiddle.com/#!3/7c1fb/2