Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ann
Posting Yak Master
220 Posts |
Posted - 2009-11-20 : 16:54:02
|
| I need to update a table with a new field based on the information (count) on another table:Table1:ID Title *PgCount(new Field - int)1 abc2 def 3 ghitable2:tbl2ID ID 1 12 13 14 25 23 3Results in Table1:ID Title *PgCount(new Field - int)1 abc 32 def 23 ghi 1I know how to do a count and I know how to do an update, what I don't know is how to combine the 2 to get the above results.Can anyone help on this?Thanks |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2009-11-20 : 17:19:10
|
| UPDATE A SET PGCount=Z.CntFROM Table1 AINNER JOIN (SELECT Tbl2ID, count(*) Cnt FROM Table2 GROUP BY Tbl2ID) ZON A.ID=Z.Tbl2ID |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|