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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:48:08+00:00 2026-05-15T16:48:08+00:00

So my database setup is fairly simple. I have a forum_cat table (a forum

  • 0

So my database setup is fairly simple.

I have a forum_cat table (a forum category) and forum_post table.

The forum_post has a field fk_forum_cat_id which ties each forum post to a category.

Each forum_post also has a field fk_parent_forum_post_id which basically says it belongs to an original post.

Further more, there is a date_added and date_edited field in forum_post.

Now, I am trying to generate the front page for my forum. I want to show a list of forum categories. Each one category should have a post count and the latest post. Could someone give me some direction with a query that does that all in one. I don’t want to run 20 separate queries!

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

    If I read your question correctly, you are seeking the category, the count of posts in the category, and the latest post in that category. Perhaps this simplification of laurent-rpnet’s answer will do the trick…

    SELECT c.forum_cat_id,
           COUNT(p.fk_forum_cat_id),
           MAX(p.date_added), 
          (SELECT p2.post_title
               FROM forum_post AS p2 
               WHERE p2.forum_cat_id = c.forum_cat_id
               ORDER BY date_added DESC
               LIMIT 1)
        FROM forum_cat AS c INNER JOIN 
                   forum_post AS p ON p.fk_forum_cat_id = c.forum_cat_id
        GROUP BY c.forum_cat_id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A simple question: I have a Model-View-Controller setup, with Models accessing a SQL database.
We have SQL Server database setup. We are setting up a replication scenarios where
I have a tomcat instance setup but the database connection I have configured in
I have a web-app-database 3 tier server setup. Web requests data from app, and
Currently we have a hybrid ASP/PHP setup connecting to a SQL Server 2005 database.
Part of the setup routine for the product I'm working on installs a database
What SQL Server Alerts do you always setup for every database? What do you
I'm working on scripts that apply database schema updates. I've setup all my SQL
I am trying to work out the best database model for the current setup:
Ok, here is my dilemma I have a database set up with about 5

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.