Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

UPDATE with SUM = possible??

2 views
Skip to first unread message

AGP

unread,
Apr 26, 2002, 11:36:53 PM4/26/02
to
I am trying to update a field1 in table1 with the
sum of a field2 in table2. the two tables are related through
dbID. There is a unique dbID in table1 that corresponds
to many dbID's in table2. I cant seem to get a SUM statement to
work in an UPDATE statement. My statement looks like so:

UPDATE table1, table2
SET table1.field1 = SUM(table2.field2)
WHERE (table1.dbID = table2.dbID);

I get an error that says i tried to execute a query that does not
include field1 as part of an aggregate function. what am i doing wrong
and how can i fix it.

tia
AGP


Kevin Mitchell

unread,
May 15, 2002, 1:30:45 AM5/15/02
to
When you use an aggregate function (Sum) you have to include all other
fields listed in the field list in a GROUP BY Clause.

change your SQL to this and it should work

UPDATE table1, table2
SET table1.field1 = SUM(table2.field2)
WHERE (table1.dbID = table2.dbID)

GROUP BY table1.field1;


"AGP" <sindiz...@softhome.net> wrote in message
news:p1py8.76489$HH5....@rwcrnsc51.ops.asp.att.net...

0 new messages