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

Top Page
Author: Hugo Mills
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] Help with SQL COUNT() statement.

Reply to this message
gpg: failed to create temporary file '/var/lib/lurker/.#lk0x580e1100.hantslug.org.uk.29339': Permission denied
gpg: keyblock resource '/var/lib/lurker/pubring.gpg': Permission denied
gpg: Signature made Wed Aug 22 14:40:00 2007 BST
gpg: using DSA key B2C27BC21C335860
gpg: Can't check signature: No public key
On Wed, Aug 22, 2007 at 12:59:59PM +0100, David Ramsden wrote:
> Initially I thought the following SQL statement would work:
>
> 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)


As pointed out, this is the full cross product -- the database
generates a row for each pair of (row from accesslog, row from
deniedlog), and then performs the count on those.

[snip]
> Can anyone help me out? I don't want to execute two seperate statements
> if possible.


Why not? It's not going to reduce the load on the server to do it
in one query -- in fact, I'd say it'll be [marginally] less load to do
two separate queries, regardless of how you do it.

Hugo.

-- 
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 1C335860 from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
        --- Summoning his Cosmic Powers, and glowing slightly ---        
                            from his toes...