I have two tables:
Table_A
= stores resultsTable_B
= to use for aggregate function
Table_A
and Table_B
share two columns called ID
and CYCLE
but Table_B
contains multiple occurrences of CYCLE
. I want to count the number of occurrences of CYCLE
in Table_B
and store them in Table_A
. For example, if for CYCLE
= 42 we have 20 rows that have the same value, I want to count that (i.e. 20) and store it in Table_A
under the CYCLE
since CYCLE
will have the same value (42) but the COUNT
column in Table_A
for that CYCLE
will contain 20. Here is what I have so far:
UPDATE database.Table_A
SET count =
(
SELECT ID, CYCLE,
COUNT(*) FROM database.Table_2
GROUP BY ID, CYCLE
)
WHERE database.Table_1.ID = database.Table_2.ID AND
database.Table_1.CYCLE = database.Table_2.CYCLE
I keep getting Error Code: 1241. Operand should contain 1 column(s)
Any suggestions for my query?
EDIT 1
The SELECT
statement returns two columns. That's what's causing Error Code: 1241
but now that that's solved, I get Error Code: 1054. Unknown column 'database.Table_2.CYCLE' in 'where clause'
.