Answer the question
In order to leave comments, you need to log in
How to get the number of replies for all nested comments?
Hey!
There is a table:
comments:
id
user_id
message
comment_id -- refers to comments
Is it possible to get the following result with an SQL query?
[
'id' => 1,
'comment_id' => null,
'replies_count' => 2,
'nested' => [
'id' => 2,
'comment_id' => 1,
'replies_count' => 1,
'nested' => [
'id' => 3,
'comment_id' => 2,
'replies_count' => 0,
],
],
],
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question