From: Collin Peters <cadiolis@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Help with simple query
Date: Wed, 28 Dec 2005 15:58:12 -0800
Message-ID: <df01c91b0512281558h3b760e89v80b4354e99183e99@mail.gmail.com> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: cadiolis@gmail.com
Subject: Re: Help with simple query
In-Reply-To: <df01c91b0512281558h3b760e89v80b4354e99183e99@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox