Help with simple query - Mailing list pgsql-sql

From Collin Peters
Subject Help with simple query
Date
Msg-id df01c91b0512281558h3b760e89v80b4354e99183e99@mail.gmail.com
Whole thread Raw
Responses Re: Help with simple query  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Help with simple query  (PFC <lists@peufeu.com>)
List pgsql-sql
I have a simple table called notes which contains notes for users.
The table has 4 columns:  note_id (auto-incrementing primary key),
user_id (foreign key to a users table), note (varchar), and
modified_date (timestamp).

Is there a nice simple query I can run that will return me a list of
all the *latest* notes for all users (users can have many notes in the
table)?  I'm trying to figure out a simple way of doing it but seem to
be having some mental block or there is no easy way to do it.

The following query will return me all the latest dates, but I can't
return the note_id or subject with it.
SELECT n.user_id, max(n.modified_date)
FROM notes n
GROUP by n.user_id
ORDER BY n.user_id

Is this simpler than I am making it?

Regards,
Collin


pgsql-sql by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: DISTINCT with NULLs and INT fields
Next
From: Tom Lane
Date:
Subject: Re: Help with simple query