Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 8DCE99FB8B0 for ; Thu, 21 Jun 2007 10:48:40 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 89394-02-6 for ; Thu, 21 Jun 2007 10:48:30 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sccrmhc12.comcast.net (sccrmhc12.comcast.net [63.240.77.82]) by postgresql.org (Postfix) with ESMTP id ADBDB9FB7CB for ; Thu, 21 Jun 2007 10:48:35 -0300 (ADT) Received: from monster.gardnerit.net (cpe-76-168-240-190.socal.res.rr.com[76.168.240.190]) by comcast.net (sccrmhc12) with ESMTP id <2007062113483301200g9384e>; Thu, 21 Jun 2007 13:48:33 +0000 Received: from localhost (monster [127.0.0.1]) by monster.gardnerit.net (Postfix) with ESMTP id 66010113081; Thu, 21 Jun 2007 06:49:47 -0700 (PDT) X-Virus-Scanned: amavisd-new at gardnerit.net Received: from monster.gardnerit.net ([127.0.0.1]) by localhost (monster.gardnerit.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id G4FuXwwcqC6w; Thu, 21 Jun 2007 06:49:46 -0700 (PDT) Received: from slapshot.local (unknown [192.168.1.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by monster.gardnerit.net (Postfix) with ESMTP id 2A30A112F1C; Thu, 21 Jun 2007 06:49:46 -0700 (PDT) Message-ID: <467A8189.2050309@gardnerit.net> Date: Thu, 21 Jun 2007 06:47:53 -0700 From: David Gardner User-Agent: Thunderbird 2.0.0.4 (Macintosh/20070604) MIME-Version: 1.0 To: Loredana Curugiu , pgsql-novice@postgresql.org Subject: Re: Select last there dates References: <1c23c8e70706210118h6b9490e3s11e2a6ba15cdff6c@mail.gmail.com> In-Reply-To: <1c23c8e70706210118h6b9490e3s11e2a6ba15cdff6c@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.517 tagged_above=0 required=5 tests=AWL=0.381, BAYES_50=0.001, FORGED_RCVD_HELO=0.135 X-Spam-Level: X-Archive-Number: 200706/152 X-Sequence-Number: 19050 I'm not sure about getting all the dates into a single comma separated field, if table two had a unique id field, say table2.id then this should retrieve the last three dates per phone number: SELECT table1.uid, table1.phone_number, table2.id, table2.date FROM table1 JOIN table2 ON table1.uid=table2.uid AND table1.phone_number=table2.phone_number WHERE table1.uid = 8 AND (table2.id IN (SELECT id FROM table2 WHERE table2.phone_number = table1.phone_number ORDER BY table2.date DESC LIMIT 3 )); -- David Gardner