Example 5.5.1 In Example 4.1.16, we obtain a list of instructors’ names and
the room numbers of their offices by projecting the table INSTRUCTORS on
name roomno.
In SQL this can be done by writing
select name, roomno from INSTRUCTORS;
The select construct used above requires the table name for the table in-
volved in the retrieval and the list of attributes that we need to extract.
In general, if we need to compute the projection of a table T on a set of
attributes A1 . . .An of the heading of T , we use the construct:
select A1, . . . ,An from T ;
Example 5.5.2 To find out the states where the students originate we project
the table STUDENTS on the attribute state. This is done by
select state from STUDENTS;
The system returns the result:
ST
--
MA
MA
MA
MA
NH
MA
MA
MA
RI
The value ’MA’ is repeated 7 times because there are seven students who live
in Massachusetts.
Duplicate values can be eliminated from a query by using the option distinct
as in
select distinct state from STUDENTS;
This will yield the answer:
ST
--
MA
NH
RI
where duplicate values have been dropped.