Re: [Hampshire] Help with SQL COUNT() statement.

Top Page

Reply to this message
Author: Kevin Bagust
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] Help with SQL COUNT() statement.
David Ramsden wrote:
> Hi all,
>
> I've got two tables in my database. One called "accesslog" and one
> called "deniedlog". They contain information from Squid and squidGuard.
> I'm trying to extract the number of requests from the accesslog and the
> number of requests from the denied log so I can display some stats.
>
> Initially I thought the following SQL statement would work:
>
> SELECT COUNT(accesslog.url) AS requests, COUNT(deniedlog.url) AS denied
> FROM accesslog, deniedlog;
>
>


Try

SELECT * from ( SELECT COUNT(accesslog.url) AS requests from accesslog )
AS requests, (select COUNT(deniedlog.url) AS denied from deniedlog) as
denied;

Which does the two counts seperatly, the same as James but rather than
an union to join them together it uses a select to join them which
should give you the single row you want.

Kevin.