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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:49:24+00:00 2026-05-30T17:49:24+00:00

I have got a table that is a result of a (My)SQL query. In

  • 0

I have got a table that is a result of a (My)SQL query. In this table I have the post creation timestamp and the user comment creation timestamp. The trick is that not all posts have a comment (so some comment_creation are NULL).

I would like to order the rows according of the most recent creation time of the post or user comment.

How can I get the max(post_creation, comment_creation) of each row and order them (DESC order)?

Thanks for all contribution.

  • 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-30T17:49:25+00:00Added an answer on May 30, 2026 at 5:49 pm

    Based on your previous question, try:

    SELECT p.id AS post_id, 
           p.author_id AS post_author_id, 
           p.created_date AS post_created,
           c.author_id AS comment_author_id,
           c.created_date AS comment_created,
           p.title, 
           c.content,
           coalesce(c.created_date,p.created_date) AS sort_date
    FROM Posts p 
    LEFT JOIN Comments c ON p.id = c.post_id
    WHERE p.author_id = $userId
    UNION ALL
    SELECT p.id AS post_id, 
           p.author_id AS post_author_id, 
           p.created_date AS post_created,
           c.author_id AS comment_author_id,
           c.created_date AS comment_created,
           p.title, 
           c.content,
           c.created_date AS sort_date
    FROM Posts p 
    RIGHT JOIN Comments c ON p.id = c.post_id
    WHERE c.author_id = $userId
    ORDER BY sort_date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a Sql Table that returns a result as follows: Amount Descrip ----------------------------
I've got a table that people have been inserting into getting the primary key
I've got a gridview that renders as a table. I have an Add button
I have got a table in an SQL Server 2008 R2 database. It contains
I have got a simple MySQL table and primary index (id) is not numbered
I've got a sub-select in a query that looks something like this: left outer
I have this query : INSERT INTO db1.outbox (DestinationNumber, TextDecoded) SELECT User.CellPhone, '$SMSMessage' as
I have got a MySql query that orders me results by no column (int,
how to write this query in sql : For every player that has played
I have a query that fetches the list of user IDs and their corresponding

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.