SQL DIFFERENCE Function Example | Difference() Method
SQL DIFFERENCE() is an inbuilt function that is used for returning the difference between the Soundex values. The Soundex value is four characters long. If two strings sound the same, then their Soundex values will be the same. If two strings sound entirely different, then none of the characters Soundex values will be the same.
SQL DIFFERENCE Function
SQL DIFFERENCE, one of the String Function, compares two SOUNDEX values and returns the integer. An integer value indicates the match for the two SOUNDEX values, from 0 to 4. The 0 indicates weak or no similarity between the SOUNDEX values. 4 indicates strong similarity or identically SOUNDEX values.
For example, peace and piece sound the same so that they will have the same Soundex values.
SELECT SOUNDEX ('piece') AS Piece, SOUNDEX ('Peace') AS Peace;
See the output.
See the following syntax.
SELECT DIFFERENCE (input_string1, input_string2);
- DIFFERENCE: Used for comparing two Soundex values.
- Input_string1, input_string_2: Strings whose Soundex values is to be considered.
- STRONG SIMILARITY
SELECT SOUNDEX('PIECE') AS PIECE, SOUNDEX('PEACE') AS PEACE, DIFFERENCE ('PIECE', 'PEACE') AS SIMILARITY;
As the Soundex values of both the strings are the same and as there is a strong similarity between them, so 4 is returned.
SELECT SOUNDEX (‘TWO’) AS TWO, SOUNDEX(‘TOO’) AS TOO, DIFFERENCE (‘TWO’, ‘TOO’) AS SIMILARITY;
See the following query.
SELECT SOUNDEX (‘COFFEE’) AS COFEE, SOUNDEX(‘LAPTOP’) AS LAPTOP, DIFFERENCE (‘COFFEE’, ‘LAPTOP’) AS SIMILARITY;
In the above query, both the strings, sounds were different, so there was a minimal similarity between two strings. 1 was returned as output because 1 character of Soundex values had a match.
SELECT SOUNDEX('Tree') AS Tree, SOUNDEX('Captivated') AS Captivated, DIFFERENCE ('Tree', 'Captivated') AS SIMILARITY;
In the above output, there is no match between any characters. So, the value returned was 0.
Finally, SQL DIFFERENCE Function Example | Understanding Difference Method is over.