| From: | Bruno Wolff III <bruno(at)wolff(dot)to> |
|---|---|
| To: | Sjors <jkwast(at)freeler(dot)nl> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: howto? |
| Date: | 2003-03-17 17:53:33 |
| Message-ID: | 20030317175333.GA21282@wolff.to |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
On Mon, Mar 17, 2003 at 18:09:31 +0100,
Sjors <jkwast(at)freeler(dot)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;
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Josh Berkus | 2003-03-17 18:00:17 | Re: Formatting intervals.. |
| Previous Message | Sjors | 2003-03-17 17:09:31 | howto? |