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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:15:00+00:00 2026-05-31T01:15:00+00:00

I am building a forum for an application and I am stuck trying to

  • 0

I am building a forum for an application and I am stuck trying to get the latest poster on a discussion. The database I am using is Oracle.

I have the following tables:

discussions
    id 
    course_id
    user_id
    title
    stub
    created_at

threads
   id
   discussion_id
   user_id
   created_at
   updated_at
   message

 discussion_views
     discussion_id
     user_id
     time

 users
     id
     username

And I have the following query:

select discussions.created_at, 
       discussions.title, 
       users.username, 
       count(threads.id) AS "replies", 
       count(distinct discussion_views.discussion_id) AS "views" 
 from discussions
 left join threads on discussions.id=threads.discussion_id
 left join discussion_views on discussions.id=discussion_views.discussion_id
 join users on users.id=discussions.user_id
 group by discussions.created_at, discussions.title, users.username
 order by discussions.created_at desc

What I need is to get the last user who posted in a thread and the date. Should I make an inner insert, a join or should I make another insert. I also want my query to be performant because my forum will need to handle a lot of traffic.

  • 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-31T01:15:01+00:00Added an answer on May 31, 2026 at 1:15 am

    Try:

    select * from
    (select discussions.created_at, 
            discussions.title, 
            users.username as discussion_created_by, 
            count(distinct threads.id) over (partition by discussions.created_at, 
                                                          discussions.title, 
                                                          users.username) AS replies, 
            count(distinct discussion_views.time) 
                 over (partition by discussions.created_at, 
                                    discussions.title, 
                                    users.username) AS "views",
            threads.user_id AS latest_post_by,
            threads.updated_at AS latest_post_at,
            row_number() over (partition by discussions.created_at, 
                                            discussions.title, 
                                            users.username
                               order by threads.id desc) AS rn
     from discussions
     left join threads on discussions.id=threads.discussion_id
     left join discussion_views on discussions.id=discussion_views.discussion_id
     join users on users.id=discussions.user_id) sq
    where rn=1
    order by created_at desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

# Explaining the context puts I am learning Rails, building a simple forum application.
# Explaining the context puts I am learning Rails, building a simple forum application.
I'm building a simple web based forum application. I want to allow users to
Am building window form application for a clinic using VS2010. On the form in
I'm building a form for searching a database inside my application, and I only
I'm building a WinForms application Window (form), inside that I'm using a FlowLayoutPanel, with
I will have a client application using a proxy to a WCF Service. This
I am building a web application using Symfony 1.4 and Doctrine for a school
I am building web application using Spring MVC Spring Security Hibenate MySQl I want
I am building wizard step demo application with MVC3 and using razor view engine

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.