I'd like to make a modification to this SELECT statement so that it only returns a single result in an array of matches; namely, the lowest Damerau-Levenshtein value that it finds. Currently I'm getting multiple pairs presented depending on how high I set the threshold in the WHERE clause (currently <6):
will result in:
That didn't line up very well... the numbers on the far right are the Damereau-Levenshtein results (DamLev). "0" is a perfect match, where "2" means it's 2 characters off. I want "<6" to be an acceptable match if there are no better matches available, but otherwise it should be discarded.
I'm pretty sure that it would involve using an array for the results and then just picking the lowest result, but I'm not sure how to implement that in the SQL. I see other threads here about arrays in SQL so I believe it's possible, but I'm not sure how to just isolate the matches and not create an array of the entire table of records.
Thanks for your thoughts...
Oh and the tables share no relationship. TCSDBOWNER_EMP. ID is a primary key and there's no key in TICO.
Code:
SELECT TCSDBOWNER_EMP.ID AS EMP_ID, TCSDBOWNER_EMP.LAST_NAME AS EMP_LNAME, TCSDBOWNER_EMP.FIRST_NAME AS EMP_FNAME, TCSDBOWNER_EMP.EMAIL_ADR AS EMP_EMAIL, TCSDBOWNER_EMP.ACTIVE_FLAG AS ACTIVE, TICO.TICO_lName, TICO.TICO_fName, TICO.TICO_Lic, TICO.TICO_SupLic, TICO.TICO_Notes, DamerauLevenshtein(TCSDBOWNER_EMP.LAST_NAME & TCSDBOWNER_EMP.FIRST_NAME,TICO.[TICO_lName] & TICO.[TICO_fName]) AS DamLev FROM TICO, TCSDBOWNER_EMP WHERE (((DamerauLevenshtein([TCSDBOWNER_EMP].[LAST_NAME] & [TCSDBOWNER_EMP].[FIRST_NAME],[TICO].[TICO_lName] & [TICO].[TICO_fName]))<6)) ORDER BY TCSDBOWNER_EMP.LAST_NAME, TCSDBOWNER_EMP.FIRST_NAME;
Code:
EMP_ID EMP_LNAME EMP_FNAME EMP_EMAIL ACTIVE TICO_lName TICO_fName TICO_Lic TICO_SupLic TICO_Notes DamLev 111111 REYNOLD MONA x T REYNOLD SANA T123456 x x 2 111111 REYNOLD MONA x T REYNOLD MONA T654321 x x 0 222222 REYNOLD SANA x T REYNOLD MONA T654321 x x 2 222222 REYNOLD SANA x T REYNOLD SANA T123456 x x 0
I'm pretty sure that it would involve using an array for the results and then just picking the lowest result, but I'm not sure how to implement that in the SQL. I see other threads here about arrays in SQL so I believe it's possible, but I'm not sure how to just isolate the matches and not create an array of the entire table of records.
Thanks for your thoughts...
Oh and the tables share no relationship. TCSDBOWNER_EMP. ID is a primary key and there's no key in TICO.
Comment