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

  • SEARCH
  • Home
  • 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 596925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:13:29+00:00 2026-05-13T16:13:29+00:00

I have a table Lets say TopicComments which records each comments from every user

  • 0

I have a table Lets say “TopicComments” which records each comments from every user on a topic. The table has TopicID and UserID as foreign keys and comment date and comment text. So for each user comment, there will be a record with TopicID, UserID, DateTime, and text.

i want to retrieve the topics with most amount of comments within lets say 5 days. Im not the guy with best SQL skills, so im kind of stuck here. Any help would be appreciated. Not sure if my question makes too much sense.

thanks in advance.

  • 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-13T16:13:30+00:00Added an answer on May 13, 2026 at 4:13 pm

    Not mentioning the RDBMS, lets say MS SQL

    SELECT  TopicID,
            COUNT(1) TotalCount
    FROM    TopicComments
    WHERE   CommentDate BETWEEN @StartDate AND @EndDate
    GROUP BY TopicID
    ORDER BY TotalCount DESC
    

    So a full example would look something like

    DECLARE @TopicComments TABLE(
            TopicID INT,
            UserID INT,
            CommentDate DATETIME
    )
    
    INSERT INTO @TopicComments SELECT 1, 1, '14 Feb 2010'
    INSERT INTO @TopicComments SELECT 1, 1, '14 Feb 2010'
    INSERT INTO @TopicComments SELECT 1, 2, '14 Feb 2010'
    INSERT INTO @TopicComments SELECT 1, 2, '14 Feb 2010'
    
    INSERT INTO @TopicComments SELECT 2, 1, '14 Feb 2010'
    INSERT INTO @TopicComments SELECT 2, 1, '14 Feb 2010'
    INSERT INTO @TopicComments SELECT 2, 2, '05 Feb 2010'
    
    DECLARE @StartDate DATETIME,
            @EndDate DATETIME
    
    SELECT  @StartDate = '10 Feb 2010',
            @EndDate = '14 Feb 2010'
    
    SELECT  TopicID,
            COUNT(1) TotalCount
    FROM    @TopicComments
    WHERE   CommentDate BETWEEN @StartDate AND @EndDate
    GROUP BY TopicID
    ORDER BY TotalCount DESC
    

    Results

    TopicID     TotalCount
    ----------- -----------
    1           4
    2           2
    

    To select the TOP 1 would then be

    SELECT  TOP 1
            TopicID,
            COUNT(1) TotalCount
    FROM    @TopicComments
    WHERE   CommentDate BETWEEN @StartDate AND @EndDate
    GROUP BY TopicID
    ORDER BY TotalCount DESC
    

    EDIT

    Use somthing like

    DECLARE @StartDate DATETIME,
            @EndDate DATETIME
    
    SET     @EndDate = DATEADD(D, 0, DATEDIFF(D, 0, GETDATE())) --returns only the date part of GETDATE()
    SET     @StartDate = @EndDate - 5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 501k
  • Answers 501k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If your code is running in-process (in excel.exe) You can… May 16, 2026 at 2:12 pm
  • Editorial Team
    Editorial Team added an answer getText should do it. you maybe need a string cast?… May 16, 2026 at 2:12 pm
  • Editorial Team
    Editorial Team added an answer Finally, I have a work around. Added hidden input elements… May 16, 2026 at 2:12 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a table (lets say it has one column called 'colLanguage') that contains
i have a table of resources (lets say cars) which i want to claim
My question is quite straightforward. I have a table, with, lets say x rows,
Lets say I have a table in a sql server 2000 database called TransactionType:
Lets say I have this table: PetID Name Age Weight How can I in
so lets say i have a table called data data id | date |
can anyone generate a query for me. Lets say i have a table sales(saleID,
Lets say I have the following table called assets with the following fields: id
Lets say you have a relational DB table like INVENTORY_ITEM. It's generic in the
Lets say I have a column of user ID's storing past login successes. Now,

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.