pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chairudin Sentosa <chairudin@prima.net.id>
To: Michael J Davis <michael.j.davis@tvguide.com>
Cc: 'Chris Bitmead' <chris.bitmead@bigfoot.com>
Cc: pgsql-sql@postgresql.org <pgsql-sql@postgreSQL.org>
Subject: Re: [SQL] Finding the "most recent" rows
Date: Fri, 23 Apr 1999 01:34:42 -0700
Message-ID: <372030A2.5468EDF4@prima.net.id> (raw)
References: <93C04F1F5173D211A27900105AA8FCFC145408@lambic.prevuenet.com>

I tried this, and did not work.

ibs=> select * from ibs_billing_record order by start_time desc limit 2;
ERROR:  parser: syntax error at or near "limit"

Regards,
Chai

Michael J Davis wrote:

> Try
> select * from the_place order by the_time desc limit 2;
>
>         -----Original Message-----
>         From:   Chris Bitmead [SMTP:chris.bitmead@bigfoot.com]
>         Sent:   Thursday, April 22, 1999 8:45 AM
>         To:     pgsql-sql@postgresql.org
>         Subject:        Re: [SQL] Finding the "most recent" rows
>
>         Try
>         SELECT the_place, max(the_time) FROM the_place GROUP BY the_place;
>
>         Julian Scarfe wrote:
>         >
>         > I have a table (representing a set of observations) with datetime
> fields and a
>         > non-unique place field.
>         >
>         > e.g.
>         > create table obs (
>         > the_time datetime,
>         > the_place char(8),
>         > ...other fields...
>         > )
>         >
>         > I'd like an efficient way to pull out the most recent row (i.e.
> highest
>         > datatime) belonging to *each* of a number of places selected by a
> simple
>         > query.
>         >
>         > e.g. given a table such as:
>         >
>         > the_time    the_place   ...
>         > 0910        London
>         > 1130        London
>         > 0910        Paris
>         > 0930        London
>         > 0840        Paris
>         > 1020        London
>         > 0740        Paris
>         >
>         > I'd like to select:
>         > 1130        London
>         > 0910        Paris
>         >
>         > Most of my attempts at this (as an SQL novice) feel very clumsy
> and
>         > inefficient. Is there an efficient way of doing this in SQL?
>         > --
>         >
>         > Julian Scarfe
>
>         --
>         Chris Bitmead
>         http://www.bigfoot.com/~chris.bitmead
>         mailto:chris.bitmead@bigfoot.com




view thread (24+ messages)  latest in thread

Message-ID: <372030A2.5468EDF4@prima.net.id>
Permalink:  ../372030A2.5468EDF4@prima.net.id/
Also on:    postgresql.org/message-id/372030A2.5468EDF4@prima.net.id

 · 

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: chairudin@prima.net.id, michael.j.davis@tvguide.com, chris.bitmead@bigfoot.com
  Subject: Re: [SQL] Finding the "most recent" rows
  In-Reply-To: <372030A2.5468EDF4@prima.net.id>
  References: <93C04F1F5173D211A27900105AA8FCFC145408@lambic.prevuenet.com> <372030A2.5468EDF4@prima.net.id>

* 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