Database Reference
In-Depth Information
If you examine Figure 6.4 you will see that although the Log table contained more than
three rows, the SELECT DISTINCT query has returned only three, and all of them contain
a unique page ID. Unfortunately, none of these rows contain the page ID 4, so no one has
viewed the resume webpage yet. It looks like I will not be changing jobs in the near future.
In a later chapter we will see how to count specific hits per page, but you can see from the
above how the simple addition of the DISTINCT command can instantly present our data
in a manner that is much easier to use. You will also realize that if our website had thou-
sands of hits in the log, this query would still produce a few rows that were easy to under-
stand.
WHERE
We have seen how to select specific columns of data using the SELECT columnname query.
This slices the table vertically. The next command will slice the table horizontally, selecting
specific rows. This is done by matching the data within a record with a set condition that is
specified in the WHERE clause, as follows:
SELECT items
FROM tablename
WHERE condition
The WHERE clause isn't only used with select statements; it can be used on any occasion
where we wish to limit a query to only apply to certain matching rows.
To illustrate the WHERE clause, the following query should tell us all the times that the
Home page (ID = 1) has been viewed in our weblog:
SELECT *
FROM
log
WHERE
webpageid = 1
Figure 6.5 show the results of this query. The query is saying: “Give me all of the rows
that contain a 1 (the ID of the Home page) in the webpageid column.” Compare this with
Figure 6.5
WHERE returns columns that match a criteria.
Search WWH ::




Custom Search