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

  • Home
  • SEARCH
  • 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 6931901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:38:14+00:00 2026-05-27T11:38:14+00:00

\d comments Table public.comments Column | Type | Modifiers ————+————————+——————————————————- id | integer |

  • 0

\d comments

                                   Table "public.comments"
   Column   |          Type          |                       Modifiers                       
------------+------------------------+-------------------------------------------------------
 id         | integer                | not null default nextval('comments_id_seq'::regclass)
 post_id    | integer                | not null
 name       | character varying(255) | not null
 email      | character varying(255) | not null
 content    | character varying(500) | not null
 created_at | date                   | 
 updated_at | date                   | 
Indexes:
    "comments_pkey" PRIMARY KEY, btree (id)

For this statement

select post_id,created_at from comments order by created_at limit 5;

I got

 post_id | created_at 
---------+------------
       5 | 2011-07-11
       5 | 2011-07-11
       5 | 2011-07-11
       8 | 2011-07-11
       2 | 2011-07-17
(5 rows)

But i need the result like this

 post_id | created_at 
---------+------------
       5 | 2011-07-11
       8 | 2011-07-11
       2 | 2011-07-17
(3 rows)

How can i rewrite the sql statement to get these three rows as result ?

\d posts

                                   Table "public.posts"
   Column    |          Type          |                     Modifiers                      
-------------+------------------------+----------------------------------------------------
 id          | integer                | not null default nextval('posts_id_seq'::regclass)
 title       | character varying(100) | not null
 content     | character varying(500) | not null
 created_at  | date                   | 
 updated_at  | date                   | 
 tags        | character varying(55)  | not null default '50'::character varying
 category_id | integer                | not null default 1
Indexes:
    "posts_pkey" PRIMARY KEY, btree (id)

With that three id from that three rows i need to get the posts.title from the posts table.
How can i write the sql statement to get the posts.title with the comments.post_id = 5 or 8 or 2 ?

  • 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-27T11:38:15+00:00Added an answer on May 27, 2026 at 11:38 am

    EDIT: Modified answer based on comment.

     SELECT p.title, q.LatestCommentDate
         FROM (SELECT c.post_id, MAX(c.created_at) AS LatestCommentDate
                   FROM comment c
                   GROUP BY c.post_id) q
             INNER JOIN posts p
                 ON q.post_id = p.id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

\d posts Table public.posts Column | Type | Modifiers -------------+------------------------+---------------------------------------------------- id | integer |
I have this recommendations table: Table public.recommendations Column | Type | Modifiers -----------------------+-----------------------------+-------------------------------------------------------------- id
Given this table: CREATE TABLE [Comments] ( [Id] [int] IDENTITY(1, 1) NOT NULL, [Text]
I have this mysql table called comments which looks like this: commentID parentID type
I'm trying to update the comments column in one table (Entries), when a new
I'm currently designing a comments table for a site I'm building. Users will be
i already created a table for comments but i want to add the feature
Is it possible to add a metadata-like description or comments to a table in
I have one table that saves comments for a varied set of content types.
I need to update the comments field in a table for a large list

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.