Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
When i run the following statement i get the following errorColumn 'Items.Label' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. SELECT TOP 5 Items.ItemID, Number=COUNT(*), Items.Availability, Items.Label, Items.Artist, Items.Title, Items.ExtraInfo, Items.mp3s, Items.ItemDescription, Items.ItemPrice, Items.ItemName, Items.released FROM Items INNER JOIN OrderItems ON Items.ItemID=OrderItems.ItemID WHERE OrderItems.Account IN (SELECT Account FROM OrderItems WHERE ItemID='" & ItemID & "') GROUP BY Items.ItemID ORDER BY Number DESCIt has something to do with the number=count(*) that is in there. How can i get around this? please help.Kris
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts
Posted - 2001-12-06 : 19:14:04
HiWhen you do a count or any other aggrigate, you need to GROUP BY everything else in your select list.In your case
Hope that helpsDamianEdited by - merkin on 12/06/2001 19:14:29
byrmol
Shed Building SQL Farmer
1591 Posts
Posted - 2001-12-06 : 19:17:47
Every column that returns a scalar value (ie Not Aggregated) must be included in the "Group By" Clause.On the other hand a item can appear in the "group by" clause without being in the "select" clauseDavidMIt gets windy at a thousand feet...."Tutorial D"