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.
| Author |
Topic |
|
phrankbooth
Posting Yak Master
162 Posts |
Posted - 2007-02-19 : 14:27:01
|
| With this query:SELECT Table1.1ID, Table1.Field1, Table2.2ID, Table2.Field1, Table3.3ID, Table3.Field1, sum(Table1.Field1), sum(Table2.Field1), sum(Table3.Field1)FROM Table1 INNER JOIN Table2 ON Table1.1ID = Table2.2ID INNER JOIN Table3 ON Table2.2ID = Table3.3IDI get this error:Column 'fieldname' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause.Is it because you can't do what I'm trying above or am I missing something?Thank you!--PhB |
|
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2007-02-19 : 15:55:55
|
| It's because 'fieldname' is contained in an aggregate function and there is no GROUP BY clause.If you ask SQL Server to aggregate (in your case sum) some of the columns in the query, then for those columns there is going to be a single total in one row, but think about it - what will go in the other columns that have not been summed? They will have multiple rows with multiple values, so you have asked SQL Server to do something illogical - return one value for some columns and multiple rows for others.You'll need to learn about the SELECT statement and aggregate functions and the GROUP BY clause.Try these placeshttp://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
|
|
|