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.
Try: