Author: Alex Date: To: Hampshire LUG Discussion List Subject: Re: [Hampshire] Help with SQL COUNT() statement.
On 8/22/07, David Ramsden <david@???> wrote: >
> <snip>
>
> SELECT COUNT(accesslog.url) AS requests, COUNT(deniedlog.url) AS denied
> FROM accesslog, deniedlog;
>
> But this gives me:
>
> +----------+--------+
> | requests | denied |
> +----------+--------+
> | 117500 | 117500 |
> +----------+--------+
> 1 row in set (0.00 sec)
I think you have a cartesian join. You're not joining the two tables
together, nor are you grouping the results.
How about:
SELECT COUNT(accesslog.url) AS requests, COUNT(deniedlog.url) AS denied
FROM accesslog, deniedlog
WHERE UPPER(accesslog.url) = UPPER(deniedlog.url);
Might be of some help, though it's off the top of my head and without really
thinking about it :)