[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index] [Date Index] [Thread Index]
[SQR-USERS Info] [SQRUG Home Page]

SQL?: Group By Within UPDATE How??



This is really more of an SQL problem than an SQR problem, but I hope
somebody knows the answer.

The problem is Combining a GROUP BY Clause with or within an UPDATE Query.
I want to UPDATE the rows in table 2 with the Counts from table 1.

Suppose 2 tables:

Table 1 "Examples"
    (Could be uniquely indexed across both columns if it mattered.)

Column1 Column2
Type:       Example:
-------  -------
Animal  Horse
Animal  Dog
Animal  Monkey
Vegie       Cabbage
Mineral Rock
Mineral     HardPlace

--------------------------

Table 2     "Counts"

Column1 Column2
Type:       CountOfExamples:
-------  ----------------
Animal  0 initially, after the query    should be 3
Vegie       0 initially, after the query    should be 1
Mineral     0 initially, after the query    should be 2

I can do a GroupBy(Examples.Type) query against table1
to generate the values 3,1,2
but how do I get them posted into Table 2?

Any solution would be welcomed, one step, two or even something that
generates an interim temp table.

Warmest thanks,

Norman Dolph