pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Louis-David Mitterrand <cunctator@apartia.ch>
To: pgsql-sql@postgresql.org
Subject: using max() aggregate
Date: Fri, 16 Jun 2000 07:52:53 +0200
Message-ID: <20000616075253.B1105@styx> (raw)

Hello,

I am trying to return the most recently updated record from a table:

SELECT max(stopdate) FROM auction;

and this works but only returns the timestamp, however if I try to get
another column with the aggregate it fails:

SELECT title,max(stopdate) FROM auction;
ERROR:  Attribute auction.title must be GROUPed or used in an aggregate function

Ok, so I group it now:

SELECT title,max(stopdate) FROM auction GROUP BY title;
     title     |          max           
---------------+------------------------
 dfsdfsdf      | 2000-07-10 05:00:00+02
 dssdfsdfsdfsf | 2000-07-09 16:00:00+02
 sdfsdfsdfsdf  | 2001-04-10 15:00:00+02
(3 rows)

But the problem is that I now get three rows when I only want the max()
item.

How should I do it?

Thanks in advance,

-- 
Louis-David Mitterrand - ldm@apartia.org - http://www.apartia.fr

"Logiciels libres : nourris au code source sans farine animale."



Message-ID: <20000616075253.B1105@styx>
Permalink:  ../20000616075253.B1105@styx/
Also on:    postgresql.org/message-id/20000616075253.B1105@styx

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: cunctator@apartia.ch
  Subject: Re: using max() aggregate
  In-Reply-To: <20000616075253.B1105@styx>
  References: <20000616075253.B1105@styx>

* 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