Help for a Sql statement
Posted
by stighy
on Stack Overflow
See other posts from Stack Overflow
or by stighy
Published on 2010-05-11T14:56:53Z
Indexed on
2010/05/11
15:04 UTC
Read the original article
Hit count: 295
sql
Hy at all, today is the day of ...question. I've a single table, with a relation master-detail like this:
RecordID MasterID Field1 Field2 .... NrDetail
1 0 xxx yyyy 1
2 0 aaaa bbbb 2
3 1 hhhhh ssss 0
4 2 eee sssss 0
5 2 jjj hhhh 0
As you can see, NrDetail contain the total of "child record". Unfortunately, i've to create this field... and i would like to write it in my table. So my SQL question is: how to do this type of SQL to write the field NrDetail ?
Something like:
UPDATE table SET NrDetail=
(SELECT COUNT(*) as Total FROM table WHERE MasterID= RecordID)
But i think there's some mistake...
Thank you in advance !
© Stack Overflow or respective owner