"Richard Davey" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> 1. SELECT SUM(IF(boardid='2',1,0)) AS b2, SUM(IF(boardid='1',1,0)) AS b1,
> COUNT(*) AS total FROM thread
> 2. SELECT SUM(IF(boardid='2',1,0)) AS b2, SUM(IF(boardid='1',1,0)) AS b1,
> COUNT(*) AS total FROM message
> This literally brings back a total number of threads and messages posted
> the two respective boards (boardid1 and 2).
> All I am wondering is if this can be combined into a single query or does
> the very nature of using the SUM(IF) not allow this to happen?
Your current queries are returning "thread count on
all groups" as a single record and "message count on
all groups" as a single record.
This is a horrible perversion of SQL.
Instead, you want a query which returns a record
with "thread count" and "message count" for each
COUNT(DISTINCT threadid) AS threads,
COUNT(*) AS messages
thread LEFT JOIN message ON message.threadid=thread.id
GROUP BY boardid ASC
WHERE boardid IN ( 1, 2 )
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php