Beginning SQL
Beginning SQL Beginning SQL
LocationId Street City State 1 Main Street Orange Town New State 2 Winding Road Windy Village Golden State 3 NULL NULL Mega State AnotherTable isn’t used again, so you can delete it from the database: DROP TABLE AnotherLocation; That’s it for INSERT INTO with SELECT for this chapter, though it returns in Chapter 8 when you learn about subqueries. Summary This chapter covered a number of topics relating to manipulating the results returned by SQL queries. Specifically you discovered that SQL has the basic four math functions dealing with addition, subtraction, multiplication, and division. Although SQL’s mathematical ability is fairly basic, it also includes a number of other math functions in addition to the fundamental four. These additional functions vary considerably among various database systems, but this chapter covered a few of the more common ones including the following: ❑ ABS(), which finds the absolute value of a number ❑ POWER(), which raises a number to a specified power (for example, squared means that a number is raised to the power of 2) ❑ SQRT(), which finds the square root of a number ❑ RAND(), which produces a fractional random number between 0 and 1 In addition to math functions, you learned that SQL also contains functions such as CEILING, FLOOR, and ROUND, which all deal with rounding up or down fractional numbers either to create a whole number or, in the case of ROUND, to reduce the number of decimal places. Furthermore, you learned that SQL has a number of functions that enable you to manipulate characterbased data. Each database system usually has a huge number of these functions, and this chapter covered the ones most commonly found in database systems including the following: ❑ SUBSTRING(), which allows you to extract part of a string from a larger string ❑ CASE() functions, which change the case of a string ❑ REVERSE(), which reverses the order of characters in a string ❑ LTRIM() and RTRIM() functions, which trim off spaces from the start or end of a string ❑ LENGTH(), which counts how many characters there are in a string Manipulating Data ❑ SOUNDEX() and DIFFERENCE() functions, which deal with matching based on how a word sounds rather than its exact spelling 187
- 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 394: FirstName DIFFERENCE(FirstName, ‘
- Page 398: Converting Different Data Types Thi
- Page 402: CREATE Table MyTable(FirstColumn in
- Page 406: The COALESCE() Function The COALESC
- Page 410: Ideally, this first argument is the
- 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
- Page 444: Chapter 6 Try It Out Selecting Data
- Page 448: Chapter 6 SELECT Category, COUNT(Fa
- Page 454: 7 Selecting Data from Different Tab
- Page 458: Selecting Data from Different Table
- Page 462: Note that MS Access insists that yo
LocationId Street City State<br />
1 Main Street Orange Town New State<br />
2 Winding Road Windy Village Golden State<br />
3 NULL NULL Mega State<br />
AnotherTable isn’t used again, so you can delete it from the database:<br />
DROP TABLE AnotherLocation;<br />
That’s it for INSERT INTO with SELECT for this chapter, though it returns in Chapter 8 when you learn<br />
about subqueries.<br />
Summary<br />
This chapter covered a number of topics relating to manipulating the results returned by <strong>SQL</strong> queries.<br />
Specifically you discovered that <strong>SQL</strong> has the basic four math functions dealing with addition, subtraction,<br />
multiplication, and division. Although <strong>SQL</strong>’s mathematical ability is fairly basic, it also includes a<br />
number of other math functions in addition to the fundamental four. These additional functions vary<br />
considerably among various database systems, but this chapter covered a few of the more common ones<br />
including the following:<br />
❑ ABS(), which finds the absolute value of a number<br />
❑ POWER(), which raises a number to a specified power (for example, squared means that a number<br />
is raised to the power of 2)<br />
❑ SQRT(), which finds the square root of a number<br />
❑ RAND(), which produces a fractional random number between 0 and 1<br />
In addition to math functions, you learned that <strong>SQL</strong> also contains functions such as CEILING, FLOOR,<br />
and ROUND, which all deal with rounding up or down fractional numbers either to create a whole number<br />
or, in the case of ROUND, to reduce the number of decimal places.<br />
Furthermore, you learned that <strong>SQL</strong> has a number of functions that enable you to manipulate characterbased<br />
data. Each database system usually has a huge number of these functions, and this chapter covered<br />
the ones most commonly found in database systems including the following:<br />
❑ SUBSTRING(), which allows you to extract part of a string from a larger string<br />
❑ CASE() functions, which change the case of a string<br />
❑ REVERSE(), which reverses the order of characters in a string<br />
❑ LTRIM() and RTRIM() functions, which trim off spaces from the start or end of a string<br />
❑ LENGTH(), which counts how many characters there are in a string<br />
Manipulating Data<br />
❑ SOUNDEX() and DIFFERENCE() functions, which deal with matching based on how a word<br />
sounds rather than its exact spelling<br />
187