Skip to content
Related Articles
Open in App
Not now

Related Articles

DIFFERENCE() Function in SQL Server

Improve Article
Save Article
  • Last Updated : 13 Oct, 2020
Improve Article
Save Article

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 :

soundex_poor soundex_pour similarity
P600 P600 4

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 :

soundex_GeeksForGeeks soundex_GFG similarity
G216 G120 2

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 :

soundex_javascript soundex_c# similarity
J126 C000 0
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!