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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:32:20+00:00 2026-06-04T04:32:20+00:00

I want my board to sort threads in the order that new threads are

  • 0

I want my board to sort threads in the order that new threads are displayed at the top until another new thread is created or a reply has been made in another thread. If this happens the thread will go down from 1 to 2 and so on.

However the code I’m using right now only does this: if a new thread is created it will be displayed at the bottom, but if you make a reply it will go to the top. So all that’s being needed to fix is making it showing the newest thread created on the top aswell.

    SELECT b.id, b.name, b.subject, b.maintext, b.ip, b.date, b.img, b.replycount, MAX(r.date)
FROM 
    board b
    LEFT JOIN reply r ON r.id = b.id

GROUP BY b.id, b.date
ORDER BY GREATEST(b.date, MAX(r.date)) DESC
LIMIT 50;
  • 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-04T04:32:20+00:00Added an answer on June 4, 2026 at 4:32 am

    greatest will return null if any of the arguments are null => i suggest using coalesce, if you care about new threads and new replies, but not about updates to the original thread:

    order by coalesce(MAX(r.date), b.date)
    

    if you care about the updates too (so b.date can be greater than max(r.date)):

    order by greatest(b.date, coalesce(MAX(r.date), b.date))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want a message board thread by default visible for a role. No need
I want to create a web-based board game like reversi. I created a similar
I want to build a maze with player that move on the maze board.
I want to to make a shared drawing board in C#. This means that
I want to create a bidimensional array that represents the positions of a board
I want to make sort of a chalk board for part of my app,
I want to hide the avatars in message board thread but I am not
I want to program a board game (similar to checkers) for the iPhone. Would
The Ok6410 board comes with android 2.3 source code (including the kernel), I want
I am building a WinCE6.0 image for VIA 8237S board. I want to include

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.