<p>Having difficulty articulating this correlated subquery.  I have two tables fictitious tables, foo and bar. foo has two fields of foo_id and total_count. bar has two fields, seconds and id.</p>

<p>I need to aggregate the seconds in bar for each individual id and update the total_count in foo. id is a foreign key in bar for foo_id.</p>

<p>I've tried something similar without much luck:</p>

<pre><code>UPDATE foo f1 set total_count = (SELECT SUM(seconds) from bar b1 INNER JOIN foo f2     WHERE b1.foo_id = f2.id) WHERE f1.foo_id = bar.id;
</code></pre>

I hope I understood your question right.
You have the following tables:
table
```
foo
```
- columns:
```
id
```
and
```
total_count
```
table
```
bar
```
- columns:
```
foo_id
```
(references
```
foo.id
```
) and
```
seconds
```
The following query should work (update all
```
total_count
```
rows in table
```
foo
```
):
```
```
UPDATE foo AS f1
SET total_count = (
  SELECT SUM(seconds) 
  FROM bar INNER JOIN foo 
  WHERE foo_id = f1.id
);
```
```
I'm not sure what you are trying to do with your last
```
WHERE
```
clause (
```
WHERE f1.foo_id = bar.id;
```
).