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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:09:22+00:00 2026-06-04T02:09:22+00:00

For now I sort all the threads in my forum using this: SELECT *

  • 0

For now I sort all the threads in my forum using this:

SELECT * FROM board ORDER BY id DESC LIMIT 50

This shows the newest thread created on the top, but how would I go about showing the thread that has the most recent reply but also showing a new thread on the top?

Example:

  1. This is a new thread
  2. This is a old thread
  3. This is a old thread

To:

  1. This is a old thread with a new reply
  2. this is a new thread without replies
  3. This is a old thread

This is the reply code if thats any help:

$sql="INSERT INTO reply (id, name, subject, maintext, ip, date, img)

VALUES

('$idid','$name','$subject','$maintext','$encoded','$date','$image_name')";

if (!mysql_query($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

mysql_query("UPDATE board SET replycount = replycount + 1 WHERE id = $idid");
  • 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-06-04T02:09:23+00:00Added an answer on June 4, 2026 at 2:09 am

    If I understand your question, you want to sort by both recent replies and newest threads. I can’t give you exact syntax without more information about your tables, but your query might look something like this:

    SELECT *
    FROM board
    ORDER BY GREATEST(replyDateTime, creationDateTime)
    LIMIT 50;
    

    This uses the GREATEST function to sort each row by either replyDateTime, or creationDateTime… whichever is more recent.

    EDIT:

    With your reply information in a separate table, your query could use a left join, and then select the most recent reply for each post in board… and then use GREATEST to select either the creation date of the post, or the most recent reply of the post.

    /* You will need to specify all your columns in board instead of using * */
    SELECT b.ID, b.CreationTimeStamp, MAX(r.CreationTimestamp)
    FROM 
        board b
        LEFT JOIN replies r ON r.BoardID = b.ID
    /* Include all your columns in your select from board here in your group by */
    GROUP BY b.ID, b.CreationTimeStamp
    ORDER BY GREATEST(b.CreationTimestamp, MAX(r.CreationTimestamp))
    LIMIT 50;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want my board to sort threads in the order that new threads are
I have records in the database with the sort order number. Now I want
I get a list of items from my Repository. Now I need to sort
In order to detect IE most Javascript libaries do all sort of tricks. jQuery
I want to use a shape of some sort for now, but would like
Ok, so I just now figured out how to sort a 2d array via
Say, I employ merge sort to sort an array of Integers. Now I need
I have a spring-based Web Service. I now want to build a sort of
I have a data with the following format: foo<tab>1.00<space>1.33<space>2.00<tab>3 Now I tried to sort
Now this isn't a question as to which of the technologies is better, since

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.