Java Reference
In-Depth Information
The queries discussed so far have been very simple, but in practice you will
frequently be using queries that depend on the values of a number of fields in various
combinations. SQL provides a number of operators to enable you to create complex
queries based on value comparisons.
Operators are used in expressions to define how to combine the conditions specified
in a WHERE clause to retrieve data or to modify data returned from a query. SQL has
several types of operators:
For convenience, SQL operators can be separated into these five main categories:
 
Comparison operators
 
Logical operators
 
Arithmetic operators
 
Set operators
 
Special-purpose operators
Comparison operators
One of the most important uses for operators in SQL is to define the tests used in
WHERE clauses. SQL supports the following standard-comparison operators, as well
as a special IS NULL operator, and its complement, IS NOT NULL, 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
Numeric and character comparisons
All the comparison operators in SQL work equally well o n both numeric and character
variables. This means that you can compare character variables using an equality
test in exactly the same way as you test a numeric value. The query:
SELECT * FROM Customers WHERE Last_Name = 'Corleone';
is every bit as valid as the query:
SELECT * FROM Inventory WHERE Part_Number = 1903;
If you use the greater-than or less-than operators for comparisons of CHAR or
VARCHAR values, the comparison is performed lexically. For example, to find
Search WWH ::




Custom Search