Java Reference
In-Depth Information
32.3.7 The like , between-and , and is null Operators
SQL has a like operator that can be used for pattern matching. The syntax to check whether
a string s has a pattern p is
s like p or s not like p
You can use the wildcard characters % (percent symbol) and _ (underline symbol) in the
pattern p . % matches zero or more characters, and _ matches any single character in s . For
example, lastName like '_mi%' matches any string whose second and third letters are
m and i . lastName not like '_mi%' excludes any string whose second and third letters
are m and i .
Note
In earlier versions of MS Access, the wildcard character is * , and the character ? matches
any single character.
The between-and operator checks whether a value v is between two other values, v1 and
v2 , using the following syntax:
v between v1 and v2 or v not between v1 and v2
v between v1 and v2 is equivalent to v >= v1 and v <= v2 , and v not
between v1 and v2 is equivalent to v < v1 or v > v2 .
The is null operator checks whether a value v is null using the following syntax:
v is null or v is not null
Query 3: Get the Social Security numbers of the students whose grades are between 'C' and 'A'.
select ssn
from Enrollment
where grade between 'C' and 'A' ;
32.3.8 Column Alias
When a query result is displayed, SQL uses the column names as column headings. Usually
the user gives abbreviated names for the columns, and the columns cannot have spaces when
the table is created. Sometimes it is desirable to give more descriptive names in the result
heading. You can use the column aliases with the following syntax:
select columnName [ as ] alias
Query 4: Get the last name and ZIP code of the students in the CS department. Display the
column headings as “Last Name” for lastName and “Zip Code” for zipCode. The query result
is shown in Figure 32.13.
F IGURE 32.13
You can use a column alias in the display.
 
 
Search WWH ::




Custom Search