Suppose I have two tables. One table, tbl1, is "long" and non-aggregated. The structure is as follows:
Software_Name:
Word
PowerPoint
PowerPoint
Excel
Word
PowerPoint
In a second Table, tbl2, I want to summarize the data from the first table, namely the count of Software. The second Table will have a structure like:
Software_Name: Count:
Word 2
PowerPoint 3
Excel 1
I have tried:
update tbl2
set count =
(select count(software_name)
from tbl1
group by software_name
where tbl1.software_name = tbl2.software_name)
from tbl1
I get a result inserted into the proper column, but it is not the proper value. It is the sum of all values, in this case 5. I have included the where
clause because in my tbl1 I have many more software_names than am interested in counting in tbl2.
UPDATE I am using Teradata Aster for this project. I have been looking at the Aster documentation for the UPDATE command and came across this:
UPDATE [ ONLY ] table
SET column = expression [, ...]
[ FROM fromlist ]
[ WHERE condition | WHERE CURRENT OF cursor_name ];
In reading about the fromlist, I came across this bit of information:
Note that the target table must not appear in the fromlist unless you intend a self-join (in which case it must appear with an alias in the fromlist).