Database Reference
In-Depth Information
If you look at the query again after the SELECT keyword, you will see that we have spec-
ified what we want from each table. The entry,
log.*
is selecting everything from the log table, whereas,
webpage.title
will just select the single column title from the webpage table. On a previous query we
selected all columns from all tables using the asterisk. You can see that using the asterisk to
select everything would be the same as using,
log.*, webpage.*
We will do one more thing to make our results tidier. If you look at Figure 7.5 again you
will see that by selecting everything from the log table we also select the foreign key
webpageID . As we already have the title of the webpage which is more useful, we do not
need to return that foreign key as well. Unfortunately, this means that we will have to spec-
ify all of the other columns in the log table instead of just using the asterisk. We will shuffle
the order of the columns slightly and use an alias as well so as to make the output look more
like the log table. Our final script will now read as follows:
SELECT
log.id as logid,
log.cookieid,
webpage.title AS pagetitle,
log.browser,
log.datecreated,
log.ipnumber,
log.referringpage
FROM
log, webpage
WHERE
webpage.id = log.webpageid
Figure 7.6 shows the results of our completed query. We've given the log 's id column the
alias logid in the output to save it getting confused with any other id columns elsewhere. We
Figure 7.5
An equi-join with selected columns.
Search WWH ::




Custom Search