pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Gaetano Mendola <mendola@bigfoot.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Select the max on a field
Date: Thu, 12 Sep 2002 07:02:06 -0700 (PDT)
Message-ID: <20020912065516.L45340-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <alq3mr$2s7o$1@news.hub.org>


On Thu, 12 Sep 2002, Gaetano Mendola wrote:

> 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)

If you don't mind using postgres extensions and
don't need a particular att_1 ordering:

select distinct on (att_2) * from test
order by att_2, att_1 desc;

Otherwise I'm not sure you can do it without
a subselect somewhere.





view thread (4+ messages)  latest in thread

Message-ID: <20020912065516.L45340-100000@megazone23.bigpanda.com>
Permalink:  ../20020912065516.L45340-100000@megazone23.bigpanda.com/
Also on:    postgresql.org/message-id/20020912065516.L45340-100000@megazone23.bigpanda.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sszabo@megazone23.bigpanda.com, mendola@bigfoot.com
  Subject: Re: Select the max on a field
  In-Reply-To: <20020912065516.L45340-100000@megazone23.bigpanda.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox