Re: a JOIN on same table, but 'slided over'

From: "hubert depesz lubaczewski" <depesz(at)gmail(dot)com>
To: "Rafal Pietrak" <rafal(at)zorro(dot)isa-geek(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: a JOIN on same table, but 'slided over'
Date: 2007-06-26 08:06:43
Message-ID: 9e4684ce0706260106p3bd7274n4229519d5afcafac@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 6/26/07, Rafal Pietrak <rafal(at)zorro(dot)isa-geek(dot)com> wrote:
>
> Is there an SQL construct to get it?
>

select
distinct on (t1.id)
t1.*, t2.*
from
test t1
join test t2 on t2.id > t1.id
order by t1.id asc, t2.id asc

should do the trick.

depesz

--
http://www.depesz.com/ - nowy, lepszy depesz

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message hubert depesz lubaczewski 2007-06-26 08:09:09 Re: data partitions across different nodes
Previous Message Achilleas Mantzios 2007-06-26 07:19:16 Re: yet another simple SQL question