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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:17:19+00:00 2026-06-03T17:17:19+00:00

I have a discussion board with the following table structure: +——————————-+ | TABLE: MESSAGES

  • 0

I have a discussion board with the following table structure:

+-------------------------------+
|       TABLE: MESSAGES         |
+-------------------------------+
| id             | int(11)      |
+-------------------------------+
| parent         | int(11)      |
+-------------------------------+
| author         | int(11)      |
+-------------------------------+
| last_reply     | datetime     |
+-------------------------------+
| written        | datetime     |
+-------------------------------+
| title          | varchar(256) |
+-------------------------------+
| content        | text         |
+-------------------------------+

The default value for last_reply is NULL. If a thread is replied, the last_reply of all messages in it will be set to the datetime of the last reply.

What I’m trying to achieve is an order of the conversations where both last_reply and written will be considered, but where the last_reply will be priorized over written when available.

So if last_reply is available, we use that value for ordering. If not, we use written.

I apologize if this is badly explained.

My best shot so far has been this:

SELECT *, COALESCE(last_reply,written) AS tmp FROM messages
WHERE parent = 0 ORDER BY written DESC, tmp DESC

This doesn’t work correctly.

If you get my point, please guide me to the correct direction 🙂

Thanks.

  • 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-03T17:17:24+00:00Added an answer on June 3, 2026 at 5:17 pm
    SELECT * FROM messages
    WHERE PARENT=0
    ORDER BY IFNULL(last_reply,written) DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table discussion of which structure is following: Table name: discussion, Id
I have a discussion board, and users can post comments on the board. But
I have a Discussion Board in a SharePoint site which has an additional column
I am writing a discussion board software that will have avatar images for the
I have a large dataset with the lifespan of threads on an discussion board.
In my discussion board I have a Post class. There are two special functions,
I have a database full of messages from a bulletin board. The board uses
I have FBA sharepoint site. I am trying to use discussion board RSS feed
How we can implement reply to reply features in Sharepoint discussion Board. I have
I have a discussion forum/blog engine working with web forms. Each post contains html

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.