Database Reference
In-Depth Information
Of course, the results in Figure 10.5 are not very user friendly. To get a more readable
output, try the following query:
SELECT webpage.title, count(*) as numberofhits
FROM log LEFT JOIN webpage
ON log.webpageid=webpage.id
GROUP BY log.webpageid
Figure 10.6 shows what happens when we use the aggregate GROUP BY along with a
LEFT JOIN to get the webpage names and an alias to get a meaningful column name.
We have now confirmed the results that we had guessed at in Figure 10.5, by making our
output more readable and meaningful. We could use the output of this query with little
reformatting on a webpage that showed the full statistics for our website.
MAX
The MAX function calculates the maximum value from a set of numeric values. One way of
using this function is:
SELECT MAX(score)
FROM
visitorbook
This will find the highest value of score that someone has entered into the visitor book.
You can see the result of running this query in Figure 10.7.
If you have a column that uses AUTONUMBER to create its ID as a primary key, you can
use a function to tell which row was the last added, by selecting the highest ID as follows:
SELECT MAX(cookieID)
FROM
cookies
If for some reason you want to manually add a key to the table without using AUTON-
UMBER, you can modify the above query as follows:
Figure 10.6
A count, GROUP BY, alias and LEFT JOIN.
Search WWH ::




Custom Search