Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 5CA84633832 for ; Wed, 26 May 2010 14:44:05 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 55035-04 for ; Wed, 26 May 2010 17:43:58 +0000 (UTC) X-Greylist: delayed 00:08:58.285488 by SQLgrey-1.7.6 Received: from smtp.go-wipex.it (mx1.go-wipex.it [89.202.235.7]) by mail.postgresql.org (Postfix) with ESMTP id 5A42B63297D for ; Wed, 26 May 2010 14:43:58 -0300 (ADT) Received: from unipex-local-server (unipex.wipex [172.16.20.247]) by smtp.go-wipex.it (Postfix) with ESMTP id 0EE6410B0087 for ; Wed, 26 May 2010 19:34:57 +0200 (CEST) Received: from [192.168.1.103] (michele [192.168.1.103]) by unipex-local-server (Postfix) with ESMTP id DE4F84508DB for ; Wed, 26 May 2010 19:34:56 +0200 (CEST) Message-ID: <4BFD5BC0.90900@unipex.it> Date: Wed, 26 May 2010 19:34:56 +0200 From: Michele Petrazzo - Unipex User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1b1) Gecko/20060724 Thunderbird/2.0a1 Mnenhy/0.7.4.0 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: inner join and limit 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.8 tagged_above=-5 required=5 tests=BAYES_50=0.8 X-Spam-Level: X-Archive-Number: 201005/113 X-Sequence-Number: 34161 Hi list, I have two table that are so represented: t1: id int primary key ... other t2: id int primary key t1id int fk(t1.id) somedate date ... other data t1: 1 | abcde 2 | fghi data t2: 1 | 1 | 2010-05-23 2 | 1 | 2010-05-24 3 | 1 | 2010-05-25 4 | 2 | 2010-05-22 5 | 2 | 2010-05-26 I'm trying to create a query where the data replied are: join t1 with t2 and return only the LIMIT 1 (or N) of the t2, with date order (of t2). Data should be: t1.id | t2.id | t2,somedate 1 | 3 | 2010-05-25 2 | 5 | 2010-05-26 As said, I'm trying, but without success... Can be done for you? Thanks, Michele