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 9109715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:06:37+00:00 2026-06-17T03:06:37+00:00

I have a table include some data like that. This is example for question/answer

  • 0

I have a table include some data like that. This is example for question/answer script. ID is auto increment and if PID=0 then it is question, when reply any question then PID is set to question’s ID. There is no Subject for replies.

ID    PID    SUBJECT                CONTENT                   DATE
1      0     First Question         This is my first          09/01/2013
2      0     Second Question        This is second            09/01/2013
3      1                            Yes this is first         09/01/2013
4      2                            I agree this is second    10/01/2013
5      0     Third Question         This is third question    11/01/2013
6      1                            Reply to first            11/01/2013
7      1                            Another reply to first    12/01/2013
8      5                            This is reply of 5th      13/01/2013
9      2                            Last try for second       14/01/2013

My questions are,

How can I select questions with reply count?

Ex.
First Question (3)
Second Question (2)
Third Question (1)

How can I select today’s answered questions or answers?

Ex. For 09/01/2013
First Question (2) ---> 1 question and 1 answer but 2 actions
Second Question (1) ---> just 1 question
  • 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-06-17T03:06:38+00:00Added an answer on June 17, 2026 at 3:06 am

    Try join for first task

    SELECT 
        q.id as ID,
        q.pid as PID,
        q.subject as SUBJECT,
        COUNT(lq.id) as Total
    FROM questions as q
    LEFT JOIN questions as lq ON lq.pid = q.ID
    WHERE q.PID = 0
    GROUP BY q.id
    

    OUTPUT

    ID  PID     SUBJECT             TOTAL
    1   0       First Question      3
    2   0       Second Question     2
    5   0       Third Question      1
    

    Demo

    EDITS :
    For second part. You should note that there can be many other ways for doing the same task.

    SELECT 
        q.id as ID,
        q.pid as PID,
        q.subject as SUBJECT,
        (COUNT(lq.id) - 1) as Total,
        q.date
    FROM questions as q
    LEFT JOIN questions as lq ON lq.pid = q.ID OR lq.id = q.PID
    WHERE q.date = DATE(NOW())
    

    OUTPUT

    ID  PID     SUBJECT             TOTAL   DATE
    1   0       First Question      2       January, 09 2012 00:00:00+0000
    2   0       Second Question     1       January, 09 2012 00:00:00+0000
    

    Demo

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

Sidebar

Related Questions

I have some data that looks like this: 1: Events 2: Event 1 3:
I have a query that produces a result like this: The data is sorted
I have a mongo table that has statistical data like the following.... course_id status
I have a table that includes some student group name, lesson time, day names
I have a table it includes 3 foreign key field like that: My Table:
I have a question about how to present some structured data using HTML. I
i have a table like this : CREATE TABLE [Mytable]( [Name] [varchar](10), [number] [nvarchar](100)
I have a data.table such as the following: a <- data.table(color=c(Red,Blue,Red,Green,Red,Blue,Blue), count=c(1,2,6,4,2,1,1),include=c(1,1,1,1,0,0,1)) > a
I have a large table I want to include in a LaTeX document. It
I have a structure where the main table is USER, other tables include CATEGORY

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.