Java Reference
In-Depth Information
When this operator is applied to the results, you would only see the Last_Name Corleone once,
despite the fact that there are several different Corleones in the table.
Note
The DISTINCT operator is very resource intensive, so you might want to consider
filtering duplicates when iterating over the ResultSet .
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, as shown in the following code:
SELECT TOP 25 PERCENT *
FROM Inventory;
The result set from running this query against a table containing 12 rows is shown in Table7-2 .
Table 7-2: ResultSet Containing the TOP 25 Percent of the Table
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.
Cross-Reference
The ORDER BY clause is discussd in Chapter 8 .
Comparison Operators
SQL supports the following standard comparison operators, as well as a special operator used to test
for a NULL value in a column:
 
Equality (=)
 
Inequality (<>)
 
Greater than (>) and greater than or equal to (>=)
 
Less than (<) and less than or equal to (<=)
 
IS NULL
 
IS NOT NULL
Using the equals and not equals operators
Comparison operators work on strings as well as on numbers. Thus, to find all records in the
Contact_Info database with a Last_Name of Corleone, you would use an equals (=) query like the
following:
SELECT * FROM Contact_Info WHERE Last_Name = 'Corleone';
 
Search WWH ::




Custom Search