Re: Doubt about join clause

From: David Wilson <david(dot)t(dot)wilson(at)gmail(dot)com>
To: jc_mich <juan(dot)michaca(at)paasel(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Doubt about join clause
Date: 2009-04-21 00:02:49
Message-ID: e7f9235d0904201702q1a1a33d0k9f9845ba17bbc09f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Apr 20, 2009 at 7:39 PM, jc_mich <juan(dot)michaca(at)paasel(dot)com> wrote:
>
> You've understood very well my problem, but also this query works as worse
> than everything I did before, it throws as many rows as rows are contained
> my tables clients and stores. I only want to find for every client what
> store is closer to him, I expect one client to one store and their distance

select clients.id as client_id, (select stores.id from stores order by
(power(clients.x-stores.x)+power(clients.y-stores.y)) asc limit 1) as
store_id from clients;

Should do the trick, or at least something very similar.

--
- David T. Wilson
david(dot)t(dot)wilson(at)gmail(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2009-04-21 00:20:47 Re: round behavior differs between 8.1.5 and 8.3.7
Previous Message jc_mich 2009-04-20 23:39:12 Re: Doubt about join clause