Beginning SQL

Beginning SQL Beginning SQL

marjan.fesb.hr
from marjan.fesb.hr More from this publisher
20.07.2013 Views

Chapter 5 176 FirstName SOUNDEX(FirstName) John J500 Jamie J500 Catherine C365 Steve S310 William W450 Stuart S363 Seymour S560 Note that you may get slightly difference results because different database systems implement slightly different versions of the SOUNDEX() algorithm. Admittedly, the results are perhaps not that useful without an in-depth understanding of SOUNDEX() and the algorithm, whose rules are fairly complex. You can learn all about the SOUNDEX() system at www.archives.gov/research_room/genealogy/census/soundex.html. However, the good news is that the DIFFERENCE() function interprets SOUNDEX() values and returns a number between 0 and 4 comparing how two strings sound. The more similar they sound, the higher the number. DIFFERENCE() takes two arguments: the two strings to be compared. The DIFFERENCE() function’s syntax is as follows: DIFFERENCE(some_name, comparison_name) Note that Oracle, MySQL, and MS Access don’t support the DIFFERENCE() function. Say, for example, that you want the details of all members whose first name sounds like Katherine or Johnny. You could use the DIFFERENCE() function to help you find those details. The following is a SQL statement that returns the difference value for Katherine and Johnny compared to values from the FirstName column: SELECT FirstName,DIFFERENCE(FirstName, ‘Katherine’), DIFFERENCE(FirstName, ‘Johnny’) FROM MemberDetails; The query results are shown in the following table: FirstName DIFFERENCE(FirstName, ‘Katherine’) DIFFERENCE(FirstName, ‘Johnny’) Katie 2 2 Susie 0 2 Doris 1 1 Jenny 1 4

Chapter 5<br />

176<br />

FirstName SOUNDEX(FirstName)<br />

John J500<br />

Jamie J500<br />

Catherine C365<br />

Steve S310<br />

William W450<br />

Stuart S363<br />

Seymour S560<br />

Note that you may get slightly difference results because different database systems implement slightly<br />

different versions of the SOUNDEX() algorithm.<br />

Admittedly, the results are perhaps not that useful without an in-depth understanding of SOUNDEX()<br />

and the algorithm, whose rules are fairly complex. You can learn all about the SOUNDEX() system at<br />

www.archives.gov/research_room/genealogy/census/soundex.html.<br />

However, the good news is that the DIFFERENCE() function interprets SOUNDEX() values and returns a<br />

number between 0 and 4 comparing how two strings sound. The more similar they sound, the higher the<br />

number. DIFFERENCE() takes two arguments: the two strings to be compared. The DIFFERENCE() function’s<br />

syntax is as follows:<br />

DIFFERENCE(some_name, comparison_name)<br />

Note that Oracle, My<strong>SQL</strong>, and MS Access don’t support the DIFFERENCE() function.<br />

Say, for example, that you want the details of all members whose first name sounds like Katherine or<br />

Johnny. You could use the DIFFERENCE() function to help you find those details. The following is a <strong>SQL</strong><br />

statement that returns the difference value for Katherine and Johnny compared to values from the<br />

FirstName column:<br />

SELECT FirstName,DIFFERENCE(FirstName, ‘Katherine’),<br />

DIFFERENCE(FirstName, ‘Johnny’)<br />

FROM MemberDetails;<br />

The query results are shown in the following table:<br />

FirstName DIFFERENCE(FirstName, ‘Katherine’) DIFFERENCE(FirstName, ‘Johnny’)<br />

Katie 2 2<br />

Susie 0 2<br />

Doris 1 1<br />

Jenny 1 4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!