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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Aggregate functions..

Author  Topic 

d confz
Starting Member

12 Posts

Posted - 2008-01-26 : 20:56:25
Hi..

I'm doing a jsp with database using sql.. I'm trying to get the max of score group by name from this table:
Table record
id_no. . . .name. . . . .score
. . 1 . . . . .Philip . . . . .10
. . 2 . . . . . Jane . . . . .12
. . 3 . . . . . John . . . . .15
. . 4 . . . . . Anna . . . . .11
. . 5 . . . . . Jane . . . . .16


I use the code:
query = "select name,max(score) from record group by name";
resultset = stmt.executeQuery (query);


However, there is an error. It says, SQL Exception: Column not found

I've checked several tutorial sites and the codes there are the same command that I use. I've also tried using other aggregate functions like the sum, still the same error comes out..

Why is that so? What should I do?

Thanks a lot..

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-01-26 : 21:27:30
First of all, develop your sql code from Query Analyzer (or Management Studio for 2005). When you have your sql working then apply it to you application code. Better yet make all you db access through Stored procedures.

Obviously you need to double check to make sure your columnName code matches the actual column names in the table. Next use square brackets around your sql object names - especially since you like to use Key Words for you object names - tsk tsk tsk...
ie: select [name], max([score]) from [record] group by [name]

Be One with the Optimizer
TG
Go to Top of Page

d confz
Starting Member

12 Posts

Posted - 2008-01-27 : 00:27:48
Thanks a lot for the help...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-28 : 00:57:37
Also use proper alias name for the aggreated columns

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -