Using SQL

Up to this point, the chapter has been about the individual aspects of a SQL statement. Following is a high-level overview of the most important SQL command, SELECT, and some of its most salient points — namely, the relational operations known as projections, selections, and joins.

Although at first glance it might appear that the SELECT statement deals only with the selection operation; in actuality, SELECT embodies all three operations. (The SELECT statement is treated in detail in Chapter 3.) Projection operations retrieve specific columns of data. Selection operations retrieve specific rows of data. And join operations bring together the data from two or more different tables.

This overly simplified example of a SELECT statement focuses more on the underlying concepts than on difficult syntax:

SELECT select_list
FROM   table_list
WHERE  search_criteria

The following statement actually embodies two of the three relational operations, selection and projection:

SELECT expense_date, expense_amount, expense_description
FROM   expenses
WHERE  employee_last_name  = 'Fudd' 
  AND  employee_first_name = 'Elmer'


Projection is the relational operation of retrieving specific columns of data. As illustrated in the prior generic example, and the more realistic example that follows, the select_list is the component of a SELECT statement that allows the programmer to perform a projection. Here, we select the first and last names of an author, plus his home state, in the authors table: ...

Get SQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.