pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: Sjors <jkwast@freeler.nl>
Cc: pgsql-sql@postgresql.org
Subject: Re: howto?
Date: Mon, 17 Mar 2003 11:53:33 -0600
Message-ID: <20030317175333.GA21282@wolff.to> (raw)
In-Reply-To: <008901c2eca7$fa181110$04a779d9@cc299057a>
References: <008901c2eca7$fa181110$04a779d9@cc299057a>

On Mon, Mar 17, 2003 at 18:09:31 +0100,
  Sjors <jkwast@freeler.nl> wrote:
> Hi,
> 
> Being not able to grasp in full sql, I've decided to call on the list. I've got a table with points, place_id and distance between points and place_id. For each point there can be more place_id's but I want to selesct the one with the minimum distance. Now I can group by the points and select the min(distance) but I can't do this if place_id is involved. I used a statment like this:
> 
> Select points, place_id, distance from table
> group by points, place_id, distance
> having count(*)>1 and distance=(select min(distance) from table

How about:
select distinct on (points) points, place_id, distance from table
order by points, distance;




view thread (5+ messages)  latest in thread

Message-ID: <20030317175333.GA21282@wolff.to>
Permalink:  ../20030317175333.GA21282@wolff.to/
Also on:    postgresql.org/message-id/20030317175333.GA21282@wolff.to

 · 

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: bruno@wolff.to, jkwast@freeler.nl
  Subject: Re: howto?
  In-Reply-To: <20030317175333.GA21282@wolff.to>

* 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