Database Reference
In-Depth Information
Retrieving the Data 6
SELECT
We have spent quite a while over the last few chapters thinking about, designing and popu-
lating our database. Now we have got some data in there, we need to get it back in a con-
trolled way.
Probably the most commonly used SQL command is the SELECT statement which
returns data from the database. The SELECT statement has various different formats, which
we will describe one by one in this chapter with examples.
The simplest form of the select statement is as follows:
SELECT *
FROM tablename
The above statement will return everything from your table. The asterisk in this context
means all columns. So the query means: “Give me all of the columns and all of the rows of
the table tablename”.
For example, to run this query on the webpage table would require the following code:
SELECT *
FROM webpage
Figure 6.1 shows the results of running this query.
With the data that is currently within our webpage table, the SELECT * results fit neatly
into the results shown in Figure 6.1. In practice, however, we rarely have this limited
amount of data. For example, our weblog table will quickly become populated by data that
will fill many screens. We can see an example of this already if we run the same query on the
log table:
SELECT
*
FROM log
Figure 6.2 shows the results of this simple query.
All of the data in the log table has been returned, as can be seen by scrolling across the
results. However, if we want to find out on which dates certain pages were viewed, scrolling
55
Search WWH ::




Custom Search