X-Original-To: pgsql-sql@postgresql.org Received: from mail6-sh.home.nl (mail6.home.nl [213.51.128.20]) by postgresql.org (Postfix) with ESMTP id 5BEE3476105 for ; Mon, 17 Mar 2003 12:09:21 -0500 (EST) Received: from cc299057a ([217.121.167.4]) by mail6-sh.home.nl (InterMail vM.5.01.05.17 201-253-122-126-117-20021021) with SMTP id <20030317170926.EAGT21331.mail6-sh.home.nl@cc299057a> for ; Mon, 17 Mar 2003 18:09:26 +0100 Message-ID: <008901c2eca7$fa181110$04a779d9@cc299057a> From: "Sjors" To: Subject: howto? Date: Mon, 17 Mar 2003 18:09:31 +0100 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0086_01C2ECB0.5BB19880" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Archive-Number: 200303/400 X-Sequence-Number: 12439 This is a multi-part message in MIME format. ------=_NextPart_000_0086_01C2ECB0.5BB19880 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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 mi= n(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=3D(select min(distance) from table This will give me 1 value being the minimum of all distances.=20 If only done on basis of points and distance I do get the minimum values, b= ut then I don't have the place_id.=20 How can I get the minimum values of the place_id within in the group of poi= nts, being the same?=20 I've looked and played around with variations round but I can't figure out = how to do this. Any suggestions??=20=20 greetz sjors ------=_NextPart_000_0086_01C2ECB0.5BB19880 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi,
 
Being not able to grasp in full sql, I've = decided=20 to call on the list. I've got a table with points, place_id and distance be= tween=20 points and place_id. For each point there can be more place_id's but I= want=20 to selesct the one with the minimum distance. Now I can group by the p= oints=20 and select the min(distance) but I can't do this if place_id is involved. I= used=20 a statment like this:
 
Select points, place_id, distance from=20 table
group by points, place_id, distance=
having count(*)>1 and distance=3D(= select=20 min(distance) from table
 
This will give me 1 value being = the=20 minimum of all distances.
If only done on basis of points and distan= ce I do=20 get the minimum values, but then I don't have the place_id.
How can I get the minimum values of t= he=20 place_id within in the group of points, being the same?
I've looked and played around with variati= ons=20 round but I can't figure out how to do this. Any=20 suggestions??  
 
greetz sjors
------=_NextPart_000_0086_01C2ECB0.5BB19880--