Databases Reference
In-Depth Information
The SQL statement to accomplish this would be:
SELECT COMMPERCT, YEARHIRE
FROM SALESPERSON
WHERE SPNUM=186;
How is this command constructed? The desired attributes are listed in the SELECT
clause, the required table is listed in the FROM clause, and the restriction or
predicate indicating which row(s) is involved is shown in the WHERE clause in
the form of an equation. Notice that SELECT statements always end with a single
semicolon (;) at the very end of the entire statement.
The result of this statement is:
COMMPERCT
YEARHIRE
15
2001
As is evident from this query, an attribute like SPNUM that is used to search
for the required rows, also known as a '' search argument ,'' does not have to appear
in the query result, as long as its absence does not make the result ambiguous,
confusing, or meaningless.
To retrieve the entire record for salesperson 186, the statement would change
to:
SELECT *
FROM SALESPERSON
WHERE SPNUM=186;
resulting in:
SPNUM
SPNAME
COMMPERCT
YEARHIRE
OFFNUM
186
Adams
15
2001
1253
The ''*'' in the SELECT clause indicates that all attributes of the selected
row are to be retrieved. Notice that this retrieval of an entire row of the table is, in
fact, a relational Select operation (see Chapter 5)! A relational Select operation can
retrieve one or more rows of a table, depending, in this simple case, on whether
the search argument is a unique or non-unique attribute. The search argument is
non-unique in the following query:
''List the salesperson numbers and salesperson names of those salespersons
who have a commission percentage of 10.''
SELECT SPNUM, SPNAME
FROM SALESPERSON
WHERE COMMPERCT=10;
which results in:
SPNUM
SPNAME
137
Baker
204
Dickens
Search WWH ::




Custom Search