Java Reference
In-Depth Information
The OR operator is used to combine two or more comparisons, any one of which can
evaluate to TRUE for the comparison to be valid. For example, to find all records in
the Customers Table who live in New York City or in New Jersey, use this query:
SELECT * FROM Customers WHERE City = 'New York' OR State = 'NJ';
Using the NOT operator
The NOT operator is used to invert the result of a comparison. For example, the
previous example can be modified as follows to find all to find all customers with a last
name of Corleone who do not live in New York City or in New Jersey:
SELECT * FROM Customers
WHERE Last_Name = 'Corleone' AND NOT ( City = 'New York' OR State = 'NJ' );
Combining logical operators using parentheses
Logical operators can be combined using parentheses (()). For example, the queries
shown in the preceding two code snippets that use the AND and OR operators can be
combined to form a query that returns all records in the Customers Table with a last
name of Corleone who live in New York City or New Jersey:
SELECT * FROM Customers
WHERE Last_Name = 'Corleone' AND ( City = 'New York' OR State = 'NJ' );
Arithmetic operators
SQL supports the common arithmetic operators for addition (+), subtraction (-),
multiplication (*), and division ( / ). In addition, SQL supports the modulo operator (%),
which returns the remainder of the division of one integer by another.
Using arithmetic operators in the WHERE clause
The first and most obvious use of arithmetic operators is in the WHERE clause. The
following example uses the LESS THAN operator to identify items in the inventory
shown in Table 3-6 with a Qty below 24:
SELECT *
FROM INVENTORY
WHERE Qty < 24;
Table 3-6: Inventory
ID
Name
Description
Qty
Cost
1001
Corn Flakes
Cereal
130
1.95
1002
Rice Krispies
Cereal
97
1.87
Search WWH ::




Custom Search