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 CD1899DC861 for ; Wed, 28 Dec 2005 20:43:16 -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 78754-06 for ; Wed, 28 Dec 2005 20:43:20 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id AF7089DC83E for ; Wed, 28 Dec 2005 20:43:14 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id jBT0hHLQ002597; Wed, 28 Dec 2005 19:43:17 -0500 (EST) To: Collin Peters cc: pgsql-sql@postgresql.org Subject: Re: Help with simple query In-reply-to: References: Comments: In-reply-to Collin Peters message dated "Wed, 28 Dec 2005 15:58:12 -0800" Date: Wed, 28 Dec 2005 19:43:17 -0500 Message-ID: <2596.1135816997@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.052 required=5 tests=[AWL=0.052] X-Spam-Score: 0.052 X-Spam-Level: X-Archive-Number: 200512/231 X-Sequence-Number: 23773 Collin Peters writes: > 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)? You can use SELECT DISTINCT ON for that, if you don't mind using a Postgres-only feature. See the "weather reports" example in the SELECT reference page. If you want to stick to portable SQL, you can still do it, but it's pretty ugly and slow. Look in the list archives for previous discussions. regards, tom lane