
638
Using the select statement
As the name Structured Query Language suggests, queries are what SQL is all
about. Thus, the select statement is the most important of the SQL state-
ments. A select statement extracts data from one or more tables in a data-
base and creates a result set containing the selected rows and columns.
In a select statement, you list the table or tables from which you want
to retrieve the data, the specific table columns you want retrieved (you
might not be interested in everything that’s in the table), and other clauses
that indicate which specific rows should be retrieved, what order the rows
should be presented in, and so on.
Here’s a simple select statement that retrieves data from a table named
movie, which contains information about your favorite movies:
select title, year
from movie
order by year
Now, take this statement apart piece by piece:
✦ select title, year names the columns you want included in the
query result (title and year).
✦ from movie names the table you want the rows retrieved from
(movie).
✦ order by year indicates that the result should be sorted into
sequence by the year column so the oldest movie appears first.
Here’s something you’ve probably wondered
ever since you first saw the letters SQL: How
do you pronounce it? Two schools of thought
exist on the subject:
✓ Spell out the letters: S-Q-L.
✓ Pronounce it like the word sequel.
Either way is acceptable, but sequel is hipper.
You can always tell how a writer pronounces
SQL by checking to see if the author writes “a
SQL query” or “an SQL query.”
You can impress even the staunchest SQL
expert by pointing out that originally, the lan-
guage was spelled SEQUEL by the IBM engi-
neers who created the first version way back
in the 1970s. SEQUEL stood for Structured
English Query Language. Someone must have
correctly pointed out that aside from borrow-
ing a few words from English such as select
and CREATE, SEQUEL actually bore no resem-
blance whatsoever to English. So English was
dropped from the name and the acronym was
shortened from SEQUEL to just SQL.
How do you pronounce SQL?
What Is SQL?
60_625873-bk08ch03.indd 63860_625873-bk08ch03.indd 638 9/21/10 10:43 PM9/21/10 10:43 PM