Org_table:
OrgName Id ParentID
Org1 20 Null
Org2 21 20
Org3 22 21
Org4 23 21
Org5 24 22
Org6 25 Null
In the table above Org1 is the super organisation and Org2 is the child of Org1. And Sub Org of Org2 is Org3 and Org4. and Org 5 is sub Org of Org3
I want to display all the details of these Org under the parent Org1 in my data grid. Here I know only the Org1 ID
so mysql query is like
Select OrgName from Org_table where ID= 20 and ParentID is 20;
But this query returns only Org1 and Org2, I have to return Org3, Org4 and Org5 also because it is under Org1. How can I do it. should I use some kind of loop if so how to do it. I am using c# do this is in my asp.net website.
During runtime I wont know which org is child of which ORg. SO I have to find the If the parent id is under the main Org
I want to do recursive query
I don’t have mysql on hand, but this should do what you need
Not sure if the syntax on the update statement is entirely correct for mysql.. might need to be tweeked a little.