Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SQL count(*) Expand / Collapse
Author
Message
Posted Tuesday, February 17, 2009 7:53 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, April 2, 2009 1:52 PM
Points: 14, Visits: 32
I would like to select top 20 rows along with count of number of rows it is selecting from a table. The following SQL (MS SQL 2000) statement gives me errors. What am I doing wrong here?

SELECT TOP 20 Id, Title, Body,
CategoryID, DatePublished, PostedBy, CommentCount, searchkeywords, isenabled, count(ID) as BlogCount
FROM BlogEntry WHERE isEnabled=1
GROUP BY DatePublished DESC

ERRORS:
Server: Msg 8118, Level 16, State 1, Line 1
Column 'BlogEntry.CommentCount' is invalid in the select list because it is
not contained in an aggregate function and there is no GROUP BY clause.
Server: Msg 8118, Level 16, State 1, Line 1
Column 'BlogEntry.searchkeywords' is invalid in the select list because it is
not contained in an aggregate function and there is no GROUP BY clause.
Server: Msg 8118, Level 16, State 1, Line 1
Column 'BlogEntry.isenabled' is invalid in the select list because it is
not contained in an aggregate function and there is no GROUP BY clause.
Post #658530
Posted Tuesday, February 17, 2009 8:28 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, May 14, 2013 1:42 PM
Points: 3,487, Visits: 1,581
When you use an aggregate function, all non-aggregate data must be included in the GROUP BY.

Greg




Post #658566
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse