Beginning SQL
Beginning SQL Beginning SQL
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
- Page 340: Chapter 4 150 Finally, you do the s
- Page 344: Chapter 4 152 SELECT * FROM MemberD
- Page 348: Chapter 4 ❑ Choose meaningful nam
- Page 354: 5 Manipulating Data In Chapter 3, y
- Page 358: The results of this query are as fo
- Page 362: You can raise a number to any power
- Page 366: To demonstrate the sort of results
- Page 370: The CEILING() Function The CEILING(
- Page 374: ased on the digits after the decima
- Page 378: The SUBSTRING() function works at t
- Page 382: LastName UPPER(LastName) LOWER(Last
- Page 386: The LENGTH() function takes just on
- Page 390: LastName LOWER(SUBSTRING(LastName,1
- Page 396: Chapter 5 Date Functions 178 Someti
- Page 400: Chapter 5 The syntax for the CAST()
- Page 404: Chapter 5 NULLs and Strings 182 NUL
- Page 408: Chapter 5 184 SELECT FirstName, Las
- Page 412: Chapter 5 186 This SQL copies over
- Page 416: Chapter 5 You also learned that mat
- Page 420: Chapter 6 190 Begin by looking at h
- Page 424: Chapter 6 This section covers queri
- Page 428: Chapter 6 194 This query gives the
- Page 432: Chapter 6 You’re almost there. Yo
- Page 436: Chapter 6 the database even though
- Page 440: Chapter 6 SELECT Category, AVG(DVDP
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