Database Reference
In-Depth Information
Figure 7.7
An equi-join query with three rows.
Restricting Equi-joins
However, our log table still only has a few rows. In this situation it is easy to look through the
result set. What if we had hundreds of rows returned by this query? If this was the case we
can just further filter the rows by adding another condition to the end of the WHERE clause:
SELECT
log.id AS logid,
webpage.title AS pagetitle,
log.browser,
log.datecreated AS logdate,
log.ipnumber,
log.referringpage,
cookies.datecreated AS cookiecreated
FROM
log, webpage, cookies
WHERE
webpage.id = log.webpageid
AND cookies.cookieid=log.cookieid
AND log.webpageid=1
Figure 7.8 shows this query running. We have restricted the whole output by looking for
the ID of 1 (the main Home page) in the results. In our example this has reduced five rows
to only three rows, but we could continue adding clauses to reduce the number further. For
instance, we could also restrict by browser or referring page to see the characteristics of
people viewing our websites from different links.
INNER JOIN - Another Format
Look again at the end of the last query:
WHERE
webpage.id = log.webpageid
AND cookies.cookieid=log.cookieid
AND log.webpageid=1
Search WWH ::




Custom Search