Skip to content
Related Articles

Related Articles

DIFFERENCE() Function in SQL Server
  • Last Updated : 13 Oct, 2020

The DIFFERENCE() function compares two different SOUNDEX values, and return the value of the integer. This value measures the degree that the SOUNDEX values match, on a scale of 0 to 4. A value of 0 indicates a weak or no similarity between the SOUNDEX values; 4 indicates that the SOUNDEX values are extremely similar, or even identical.

Syntax :

DIFFERENCE(string, string)

Parameter : This method accepts two-parameters as mentioned above and described below –

  • string, string –
    It is an alphanumeric expression of character data. It can be a constant, variable, or column.

Returns : It returns an integer value measuring the difference between the SOUNDEX() values of two different string.

Example-1 :
Using DIFFERENCE() function with similar SOUNDEX() values.

SELECT SOUNDEX('poor') soundex_poor, SOUNDEX('pour') soundex_pour, 
DIFFERENCE('poor', 'pour') similarity;

Output :


Example-2 :
Returns a DIFFERENCE value of 3, the less possible difference.

SELECT SOUNDEX('GeeksForGeeks'), SOUNDEX('GeeksOfGeeks'),
DIFFERENCE('GeeksForGeeks', 'GeeksOfGeeks');

Output :


Example-3 :
Returns a DIFFERENCE value of 2, the medium possible difference.

SELECT SOUNDEX('GeeksForGeeks') soundex_GeeksForGeeks, SOUNDEX('GFG') soundex_GFG,
DIFFERENCE('GeeksForGeeks', 'GFG') similarity;

Output :


Example-4 :
Returns a DIFFERENCE value of 0, the highest possible difference.

SELECT SOUNDEX('javascript') soundex_javascript, SOUNDEX('c#') soundex_c#,
DIFFERENCE('javascript', 'c#') similarity;

Output :

My Personal Notes arrow_drop_up
Recommended Articles
Page :