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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:53:05+00:00 2026-05-31T11:53:05+00:00

I am building a forum using Oracle as my rdbms and I am having

  • 0

I am building a forum using Oracle as my rdbms and I am having problems with 1 query that fetches all the forum posts and displays some data. The issue I am having is getting the last discussion poster. With my query I only managed to get the last poster’s id , but I want to get his username from the users table. This is what I have:

I have the following schema:

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 make this query:

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.discussion_id) 
             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

I am getting latest_post_by as id , I want to display the username

  • 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-31T11:53:07+00:00Added an answer on May 31, 2026 at 11:53 am

    In response to your comment, add another join to the users table.

    join users latest_poster ON (latest_poster.id=threads.user_id)
    

    Then replace:

    threads.user_id AS latest_post_by
    

    with:

    latest_poster.username AS latest_post_by
    

    This should then give you the username of the user identified by threads.user_id.

    Hope it helps…

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

Sidebar

Related Questions

I'm building a forum software and am trying to grab all the posts by
I'm currently building a web form using APEX that is losely modelled after a
I've recently begun working on a project regarding GUI building using some form of
I'm building a basic forum where every post contains some text, first and last
In my forum that I am building, I want to get information about users
I'm building a small scale forum script in PHP, and I am having difficulty
I'm building an Outlook 2010 add-in that will tie into our ticketing system using
I'm building a forum that will allow users to upload images. Images will be
I am building my rails app and using forem to integrate forum in it.
I'm building a form in ASP.NET MVC3 + Razor that posts to a PHP

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.