Hi All,
I am writing my own forum software for the site I'm developing (I prefer to write my own software than use pre-made scripts...)
I have the following SQL Stored Procedure to list the forums in a particular category:
Code:
CREATE PROCEDURE [dbo].[GetForums]
@sect_ID int
AS
SELECT
*
FROM
Forums
WHERE
frm_SectionID = @sect_ID
GO
This works fine. Now what I want to do is add in the thread count for each forum, so I changed the query to:
Code:
CREATE PROCEDURE [dbo].[GetForums]
@sect_ID int
AS
SELECT
Forums.*,
Count(Threads.thr_ID) As frm_ThreadCount
FROM
Forums, Threads
WHERE
frm_SectionID = @sect_ID AND Threads.thr_Forum = frm_ID
GO
This doesn't work. It returns an error saying each of the columns in Forums cannot be added to the SELECT because they're not part of an aggrogate function o in the GROUP BY clause. I've read up on it and the only suggestions people have is to put the columns in the GROUP BY clause - which I can't exactly do (Can't do GROUP BY Forums.*)
Is there another way I can get around this?
- Mina
|