Java Reference
In-Depth Information
When this operator is applied to the results, you see only the last name "Corleone"
once, despite the fact that there are several different Corleones in the table.
There is also a keyword ALL, as in SELECT ALL, but since ALL is implied
unless DISTINCT is used, the expression SELECT ALL is rarely, if ever,
used.
Note
The TOP operator
The TOP operator specifies that only the first n rows are to be output from the query
result set, or, optionally, the top n percent of the rows. When specified with
PERCENT, n must be an integer between 0 and 100:
SELECT TOP 25 PERCENT *
FROM Inventory;
The result set from this query is shown in Table 3-8 .
Table 3-8: Top n Records
ID
Name
Description
Qty
Cost
1001
Corn Flakes
Cereal
130
1.95
1002
Rice Krispies
Cereal
97
1.87
1003
Shredded Wheat
Cereal
103
2.05
If the query includes an ORDER BY clause, the first n rows (or n percent of rows)
ordered by the ORDER BY clause are output. If the query has no ORDER BY clause,
the order of the rows is arbitrary.
Escape Sequences
Escape sequences are used to handle situations where a character has a
particular meaning to SQL, and you want to use it in a different way. A typical
example is the use of the apostrophe ('). A problem that arises frequently in
normal free-form text is the use of the apostrophe. Since the apostrophe is, in
effect, a single quote, SQL reads it as a CHAR or VARCHAR terminator and
throws a SQL error when it tries to handle the rest of the String.
The solution is simple: simply double up the apostrophe. These two other
characters sometimes need to be escaped:
  % percent
  _ underscore
 
Search WWH ::




Custom Search