Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. SELECT contacts.id
  2. FROM contacts
  3. INNER JOIN (
  4. SELECT first_name, last_name, count(*) AS rows
  5. FROM contacts
  6. WHERE deleted = 0
  7. GROUP BY SOUNDEX(first_name), SOUNDEX(last_name)
  8. HAVING count(rows) > 1
  9. ) AS p
  10. WHERE contacts.deleted = 0
  11. AND p.first_name SOUNDS LIKE contacts.first_name
  12. AND p.last_name SOUNDS LIKE contacts.last_name
  13. ORDER BY contacts.date_entered DESC
  14.  
  15. [...] AND SOUNDEX(p.first_name) = SOUNDEX(contacts.first_name) [...]
  16.  
  17. SELECT c1.id as contact_id,
  18. c2.id as similar_id
  19. FROM contacts c1
  20. JOIN contacts c2
  21. ON c2.id <> c1.id
  22. AND c2.deleted = 0
  23. AND SOUNDEX(c2.first_name) = SOUNDEX(c1.first_name)
  24. AND SOUNDEX(c2.last_name) = SOUNDEX(c1.last_name)
  25. WHERE c1.deleted = 0
  26. ORDER BY c1.date_entered DESC
  27.  
  28. SELECT c1.id as contact_id,
  29. c2.id as similar_id
  30. FROM contacts c1
  31. JOIN contacts c2
  32. ON c2.id <> c1.id
  33. AND c2.deleted = 0
  34. AND c2.first_name_soundex = c1.first_name_soundex
  35. AND c2.last_name_soundex = c1.last_name_soundex
  36. WHERE c1.deleted = 0
  37. ORDER BY c1.date_entered DESC
  38.  
  39. SELECT SOUNDEX('cholmondley');
  40. +------------------------+
  41. | SOUNDEX('cholmondley') |
  42. +------------------------+
  43. | C4534 |
  44. +------------------------+
  45.  
  46. SELECT SOUNDEX('chumleigh');
  47. +----------------------+
  48. | SOUNDEX('chumleigh') |
  49. +----------------------+
  50. | C542 |
  51. +----------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement