Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



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

Posts: 1,626
Location: Guildford, UK
Trades: 0
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!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
 
Register now for full access!
Reply     « Reply to SQL - Adding a Count() in with standard columns
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.07894 seconds with 12 queries