OrganisationID OrganisationName parentID
1 Org1 Null
2 Org2 1
3 Org3 1
4 Org4 2
5 Org5 2
6 Org5 4
Table Name is tbl_Organisation
I am having a table similar to this. All I am trying is to retreive the Sub Organisation and display it. Suppose the Org ID passed is 3, then the Org3 doesnt have any child so it displays only Org3. Suppose if OrgID =2 then the Org2 has a child Org4 and Org4 has a child Org5. So for OrgID=2 I have to display Org2, Org4 and Or5. SO how can I do that. I have tried few things but it didn't work as I intended.
SELECT distinct b.OrganisationID,b.OrganisationName
FROM tbl_organisation as a LEFT OUTER JOIN tbl_organisation as b
on a.OrganisationID=b.ParentID where a.OrganisationID=b.parentID
Tell me where I am wrong I am using this in asp.net website, I am using c# and mysql