Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 34BC0475EC8 for ; Thu, 12 Sep 2002 09:09:49 -0400 (EDT) Received: from news.hub.org (news.hub.org [64.49.215.80]) by postgresql.org (Postfix) with ESMTP id AD8BB475EBB for ; Thu, 12 Sep 2002 09:09:48 -0400 (EDT) Received: by news.hub.org (Postfix, from userid 8) id 81BEE381BA5; Thu, 12 Sep 2002 09:09:47 -0400 (EDT) From: "Gaetano Mendola" X-Newsgroups: comp.databases.postgresql.sql Subject: Select the max on a field Date: Thu, 12 Sep 2002 15:09:53 +0200 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 46 Message-ID: X-Complaints-To: news@hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 To: pgsql-sql@postgresql.org X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/97 X-Sequence-Number: 9374 Hi all, Suppose that I have a table like this: att_1 | att_2 | att_3 | att_4 -------------------------------- 1 | a | y | y1 2 | b | y | y2 3 | a | xx | y3 4 | c | zz | y4 5 | a | t | y5 6 | c | x | y6 I want obtain all row that have for each att_2 the max of att_1 some like SELECT * FROM MY_TABLE GROUP BY att_2 HAVING att_1 = max ( id_user_log) for obtain: att_1 | att_2 | att_3 | att_4 -------------------------------- 2 | b | y | y2 5 | a | t | y5 6 | c | x | y6 Ciao Gaetano