Java Reference
In-Depth Information
The IN operator
The IN operator is a powerful way of comparing fields against a list. For example, to
find contacts in New York State or New Jersey, you can use this query:
SELECT *
FROM Customers
WHERE State IN ('NY', 'NJ');
IN also works with numbers. If you want to select items from the Inventory Table by ID ,
use this query:
SELECT *
FROM Inventory
WHERE ID IN (1001, 1003, 1004);
The BETWEEN operator
The BETWEEN operator is used to select fields with values between specified limits.
Referring again to the Inventory Table, you can query for items with costs in the $1.03
to $1.95 range using this query:
SELECT *
FROM Inventory
WHERE Cost BETWEEN 1.03 AND 1.95;
BETWEEN returns values within its defined range inclusive of the limits,
so if you try the query against the Inventory Table, it will return rows with
costs of 1.03 and 1.95.
Note
The DISTINCT operator
A basic SELECT statement tells the database management system to return all
records matching the query in the ResultSet. For example, you cab request all
Last_Names from customers using this query:
SELECT Last_Name
FROM Customers;
Using the data shown in Table 3-4 , this gives you five repetitions of "Corleone."
The DISTINCT operator tells the database management system not to return
duplicate records in a ResultSet. For example, to return all Last_Names from the
Customers Table with no duplicates, use this query:
SELECT DISTINCT Last_Name
FROM Customers;
Search WWH ::




Custom Search