Reply
SQL - Adding a Count() in with standard columns
Old 08-04-2005, 07:57 AM SQL - Adding a Count() in with standard columns
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
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
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Inoxia Pyrotechnics Supplies | Surrey Angels Cheerleading Squad
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
When You Register, These Ads Go Away!
     
Reply     « Reply to SQL - Adding a Count() in with standard columns
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12054 seconds with 13 queries