select BoardID,BoardName,
(select count(*) from tbl where ParentID=a.BoardID) as ChildCount
from tbl as a
where ParentID=0
(select count(*) from tbl where ParentID=a.BoardID) as ChildCount
from tbl as a
where ParentID=0
BoardName,
ChildCount=(select count(1) from tb where BoardID=a.BoardID)
from tb a
where ParentID=0
from tablename a innerjoin tablename b
on a.BoardID = b.ParentID
from tablename a inner join tablename b
on a.BoardID = b.ParentID