From: Peter Brawley Date: September 27 2006 2:49pm Subject: Re: Count of children List-Archive: http://lists.mysql.com/mysql/202137 Message-Id: <451A8F69.5000809@earthlink.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit André, >I want the count of all sub-entries for a specific entry. Depends on the model you are using--edge list or nested sets? PB ----- André Hänsel wrote: > I have a table with id and parent_id. > I want the count of all sub-entries for a specific entry. > > I found several documents about working with graphs/trees in MySQL but I > could not find a solution for my problem. > > I can imagine two possibilities, but one is memory intensive and the other > one creates load on updates. > The first is, that I select all entries and then use a procedural language > to determine recursively whether an node is a sub-node of the specific node. > The second is, that I store the sub-node count with each node and when I do > an insert, I walk the tree upwards and increment the node-counts. > > Is there a smart solution/best practice for my problem? > > Now I can't think of another sentence starting with an i. ;-) > > Best regards, > André > > > -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.407 / Virus Database: 268.12.9/457 - Release Date: 9/26/2006