X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0EDD69DC84E for ; Wed, 28 Dec 2005 19:58:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 68467-06 for ; Wed, 28 Dec 2005 19:58:14 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.196]) by postgresql.org (Postfix) with ESMTP id 7DE859DC810 for ; Wed, 28 Dec 2005 19:58:09 -0400 (AST) Received: by wproxy.gmail.com with SMTP id i22so1346840wra for ; Wed, 28 Dec 2005 15:58:12 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=kQWmkhaFMmdfekOOvMU9cGXqKcsXfjSEnCbvkYTRlRSUqnqyr4HfXYid59J9FsjpBSKGoAUZVx3IYgexInnxk7v7ik1bMqtxZvJzIgkPupO+QKMGwf8saNyjwyqTnEdRLQpu1qw1ybSuhAFu+KyDpEQpM+ICJCgJGGwacCdPo58= Received: by 10.65.232.11 with SMTP id j11mr3159508qbr; Wed, 28 Dec 2005 15:58:12 -0800 (PST) Received: by 10.65.159.6 with HTTP; Wed, 28 Dec 2005 15:58:12 -0800 (PST) Message-ID: Date: Wed, 28 Dec 2005 15:58:12 -0800 From: Collin Peters To: pgsql-sql@postgresql.org Subject: Help with simple query MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200512/230 X-Sequence-Number: 23772 I have a simple table called notes which contains notes for users.=20 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