Imar: It depends. Consider this code:
declare @tbl table (value int, userID int)
INSERT INTO @tbl (value, userID)VALUES(10, 1)
INSERT INTO @tbl (value, userID)VALUES(10, 1)
INSERT INTO @tbl (value, userID)VALUES(10, 1)
INSERT INTO @tbl (value, userID)VALUES(10, 1)
INSERT INTO @tbl (value, userID)VALUES(10, 2)
INSERT INTO @tbl (value, userID)VALUES(10, 2)
SELECT sum(value), userID from @tbl where userID = 1
this will return you a resultset of 40 if, however, you do:
SELECT sum(value), userID from @tbl group by userID
Your resultset will be
Value UserID
40 1
20 2
You only need a group by clause if you are selecting data from a column and you are not using an aggregate function on it, so in my last examle if i were to have done
SELECT sum(value), userID from @tbl where userID = 1
this would have generated a SQL error but simply having SELECT Sum(value) without a group by clause is perfectly legal.
kj, i completely understand that the data will not be known at runtime, i was using the code i provided (using the values you had provided) to illustrate how this would be done in SQL. You could potentially have 1000 rows of data for one user and calling Sum() will return you the sum of all values in that column for that user.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========