Information Modeling and Relational Databases: From Conceptual Analysis to Logical Design

Recall that relational algebra includes the following eight table operations: union, intersection, difference, Cartesian product, selection, projection, join, and division. All of these operations (as well as others) can be expressed using SQL s powerful select statement. This section discusses how SQL is used to perform relational projection and selection, as well as bag projection and row ordering.
First let s see how to choose columns. Consider a small UoD where people are identified by their first name. Table 11.8 provides sample data for the table scheme: Person ( firstname , sex, starsign, birthyr). The whole table may be retrieved by projecting on all its columns. In relational algebra this may be formulated as Person, or as Person [ firstname, sex, starsign, birthyr ] . In SQL, this is expressed as follows:
<b class="bold">select</b> * <b class="bold">from</b> Person

Here the asterisk * means all columns and may be read as everything or all . The table named after from indicates the table from which the data is to be retrieved. When this command is executed, the result is an unnamed table with the same column names and contents as the original Person table.
If only some of the columns are required, then instead of * the relevant columns should be listed (separated by commas). If the columns include a key, no duplicate rows can occur in the result, so the result corresponds...