Java Reference
In-Depth Information
For example, to find all records in the Customers Table with last names starting with
"C," write a query using LIKE as follows:
SELECT * FROM Customers WHERE Last_Name LIKE 'C%';
Similarly, to find all records where the last name contains the letter "o" in the second
place, the q uery looks like this:
SELECT * FROM Customers WHERE Last_Name LIKE '_o%';
NOT LIKE works in much the same way as LIKE. For example, to find all records in
the Customers Table with the last name NOT starting with the letter "C," write a query
using NOT LIKE such as the following:
SELECT * FROM Customers WHERE Last_Name NOT LIKE 'C%';
Using the concatenation operator
The concatenation operator (+ or ||) is used to append one string to another string.
For example, to return the last name, followed by the first name and separated by
commas, use this query:
SELECT Last_Name + ', ' + First_Name AS NAME FROM Customers;
The concatenation operator is one of the SQL features that vary from
one flavor of SQL to another. SQL Server, MS Access, and Sybase, fo r
example, accept '+', whereas Oracle accepts '||'.
Caution
Logical operators
It is frequently necessary to combine two or more comparisons in a WHERE clause.
SQL provides these standard logical operators for this purpose:
 
AND
 
OR
 
NOT
Using the AND operator
The AND operator is used to combine two or more comparisons, all of which must
evaluate to TRUE for the comparison to be valid. If either expression is false, AND
returns FALSE. For example, to find all records in the Customers Table with a last
name of Corleone who live in New York, use this query:
SELECT * FROM Customers WHERE Last_Name = 'Corleone' AND City = 'New York';
Using the OR operator
Search WWH ::




Custom Search