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 |
|
badinar
Starting Member
14 Posts |
Posted - 2008-09-19 : 12:07:07
|
| i have two tables Category Table---------------IdNameNumberOfProductsProducts---------idCategoryIdProductNameI'm trying to update the NumberOfProducts Column of the category tablewith this update statement but does not work.update Categoryset NumberOfProducts=(select count(*) from Products p where id = p.CategoryID)some help pleaseThanks, |
|
|
bjoerns
Posting Yak Master
154 Posts |
Posted - 2008-09-19 : 12:30:45
|
| What does not work? Update does nothing? Error message? Query deletes Product table? Server shutdown? |
 |
|
|
badinar
Starting Member
14 Posts |
Posted - 2008-09-19 : 12:37:22
|
| update just puts 0 on all rows. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-19 : 12:51:35
|
it should be this i guessupdate cset c.NumberOfProducts=p.ProductCountFROM Category cINNER JOIN(select CategoryID,count(*) AS ProductCount from Products GROUP BY CategoryID)pon c.id = p.CategoryID |
 |
|
|
badinar
Starting Member
14 Posts |
Posted - 2008-09-19 : 13:08:59
|
| That it visakh16!!. Just like that!! thanks a lot!! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-19 : 13:11:13
|
quote: Originally posted by badinar That it visakh16!!. Just like that!! thanks a lot!!
welcome |
 |
|
|
|
|
|