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
You can use it:
SELECT parent_id, count( * )
FROM table
WHERE parent_id =1
GROUP BY parent_id
It´ll works fine.
André Hänsel [EMAIL PROTECTED] escreveu na mensagem
news:[EMAIL PROTECTED]
I have a table with id and parent_id.
I want the count of all sub-entries for a specific entry.
I found
André,
Your sentence 'I want the count of all sub-entries for a specific entry'
converts straight into SQL:
'I want'
SELECT
the count of all entries
COUNT(*) FROM myTable
with a specific parent
WHERE parent_id = 5
You've missed one of the major benefits of SQL - it's designed to
]
Gesendet: Mittwoch, 27. September 2006 15:48
An: André Hänsel; mysql@lists.mysql.com
Betreff: re: Count of children
André,
Your sentence 'I want the count of all sub-entries for a
specific entry' converts straight into SQL:
'I want'
SELECT
the count of all entries
COUNT
; mysql@lists.mysql.com
Betreff: re: Count of children
André,
Your sentence 'I want the count of all sub-entries for a
specific entry' converts straight into SQL:
'I want'
SELECT
the count of all entries
COUNT(*) FROM myTable
with a specific parent
WHERE parent_id = 5
/ \
D E
\
F
So I want to know that C has 3 sub-nodes.
-Ursprüngliche Nachricht-
Von: Rob Desbois [mailto:[EMAIL PROTECTED]
Gesendet: Mittwoch, 27. September 2006 15:48
An: André Hänsel; mysql@lists.mysql.com
Betreff: re: Count of children
André,
Your sentence
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
. September 2006 16:49
An: André Hänsel
Cc: mysql@lists.mysql.com
Betreff: Re: Count of children
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
Hänsel; mysql@lists.mysql.com
Betreff: re: Count of children
André,
Your sentence 'I want the count of all sub-entries for a
specific entry' converts straight into SQL:
'I want'
SELECT
the count of all entries
COUNT(*) FROM myTable
with a specific parent
WHERE parent_id = 5
You've
I've found this website to be extremely helpful:
http://www.artfulsoftware.com/mysqlbook/sampler/mysqled1ch20.html
Donna DeVaudreuil
André Hänsel [EMAIL PROTECTED]
09/27/2006 10:55 AM
To
[EMAIL PROTECTED]
cc
mysql@lists.mysql.com
Subject
AW: Count of children
I will use any model
in either of them.
-Ursprngliche Nachricht-
Von: Peter Brawley [mailto:[EMAIL PROTECTED]]
Gesendet: Mittwoch, 27. September 2006 16:49
An: Andr Hnsel
Cc: mysql@lists.mysql.com
Betreff: Re: Count of children
Andr,
I want the count of all sub-entries for a specific
Hänsel
Cc: mysql@lists.mysql.com
Subject: Re: AW: Count of children
André
With an edge list, the solution entails recursion, so you need either an sproc
or application proc. With a nested sets model, the count is dead simple. If the
id of the target row is N, and the left right node columns
12 matches
Mail list logo