Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7638493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:11:29+00:00 2026-05-31T08:11:29+00:00

I am making a nested comment system, and I have the following table: create

  • 0

I am making a nested comment system, and I have the following table:

create table comments (
id int unsigned primary key auto_increment,
author_id int unsigned not null,
target_id int unsigned not null,
target_type set('post','comment') not null,
content varchar(2000) not null
);

Each comment may be targeting a post, or another comment, in which case it would be considered a reply. Is there a simple way to count the number of nested comments (comments + replies + replies to replies, etc.) to a given post (say, a post with id 1)?

I know that if I had a field called target_post_id and another called target_comment_id, instead of having target_id and target_type, it would be very easy to count all the comments for any given post, but I have reasons for trying to keep this table structure, and truth be told, I’ve never dealt with recursive queries before. Any help is appreciated, thanks!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:11:31+00:00Added an answer on May 31, 2026 at 8:11 am

    The short answer is “no”. The slightly longer answer is that you could keep a comment count on the overall post, and update it as you add/delete comments in your nested structure (which is denormalising, but not entirely unexpected in this kind of situation); or as you point out you can always point back to the post from every comment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are these nested comments allowed in a XML file? <!-- Making only one observation
I have this massive nested loop scenario that is calling the DB and making
I'm making a sub nav in wordpress and have a nested list style menu.
I have a several tables nested within a table that I am parsing using
I have a table such as the following: mafiadb:{Etzli:{alive:50,mafia:60,vigilante:3,doctor:4,citizen:78,police:40},Charneus:{alive:29,mafia:42,vigilante:6,doctor:14,citizen:53,police:33}} There are more nested tables,
I am trying to exclude nested tables from my table striping (making every other
I have nested list of the following form: my_list = [['Some1', '2', '3.6', '4.5',
I am making a videos website where categories will be nested: e.g. Programming-> C
Making my first steps with NHibernate, I'm trying to have it creating my Tables
i am using the following nested xpath query $xpath->query('//ul[@id=ref_1000]/li[not(strong)][//span[@class=refinementLink]]'); what i want is search

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.