2

In python there a nice built in function that lets me check the difference between the sequence of two strings. Example below:

from difflib import SequenceMatcher

def similar(a, b):
    return SequenceMatcher(None, a, b).ratio()

Example:

similar("Apple","Appel")
0.8
similar("Apple","Mango")
0.0

Is there an equivalent function in SQL?

What I need to do is join two tables on a column. On table A, this column is their actual account number, on the other table the column is the user adding their account number which isn't a required field and because of that I've noticed that there are slight variations in their actual account number.

Table A

account_num   Name
5WWW55        John
DDDDD7        Jacob
SSSSX7        jingleheimer

Table B

account_num   Name
5WWW55        John
3SSSX7        jingleheimer     -- First character is different 


Select Table_A.account_num, 
       Table_b.Name 
FROM Table_A
JOIN TABLE_B 
          on Table_A.account_num = Table_B.account_num

Expected output:

account_num   Name
5WWW55        John
SSSSX7        jingleheimer
CandleWax
  • 2,159
  • 2
  • 28
  • 46

2 Answers2

2

You could use DIFFERENCE:

SELECT Table_A.account_num, 
       Table_b.Name 
FROM Table_A
JOIN TABLE_B 
  ON DIFFERENCE(Table_A.account_num , Table_B.account_num) = 4;

db<>fiddle

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275
0

Levenshtein distance might be what you are looking for. I've used it before to compare similarity between strings in SQL server.