Hi all,
I have the following requirement.
Parent child mapping table
ID ParentID ChildID
1 1 2
2 1 3
3 2 4
3 2 5
3 4 6
Main Table
ID ViewCount
1 3
2 4
3 4
4 5
5 6
The Parent and childs are present in the same table itself and having their own viewcounts.
Whne I read any record it has to get the particular records viewcount as well as their child's view count.
I have updated only the particular records viewcount, not updated their parents.
So from the main table, When I access the record with ID 1, it has to get all of their childs viewcount and its own viewcount. for this case 22.
when i access 2 the viewcount is 15.There is no level into that, it will grow in accordance with childs.
How to write a query or redesign the table or anything
to implement the above requirement?
The ID column present in the main table refers both Parent and child ID's and its the primary key also. In the mapping table we are mapping the parent & child relationship. ID present in the parent/child table is table's primary key field.Right there is no use of that field