I have SQL update query problem. I would like to be able to update one table using the results of a query against another table. Here is a simple example to show what I would like to do.
I have two tables:
TABLE1
ID COUNT
1 0
2 0
3 0
Table2
ID
1
1
1
2
select id,count(*) from table2 group by id;
ID COUNT
1 3
2 1
I can update one row at a time using this syntax:
update table1 set count=(select count(*) from table2 where id=1 group by id) where id=1;
What I would like is to be able to update all rows with one single sql statement so that the result would be:
TABLE1
ID COUNT
1 3
2 1
3 0
Any ideas?
I think this might work for you: