Re: Finding sequential records - Mailing list pgsql-sql

From Richard Broersma
Subject Re: Finding sequential records
Date
Msg-id 396486430809261102j73869b8es6b325621bcfe1ea6@mail.gmail.com
Whole thread Raw
In response to Finding sequential records  (Steve Midgley <science@misuse.org>)
Responses Re: Finding sequential records  ("Richard Broersma" <richard.broersma@gmail.com>)
List pgsql-sql
On Fri, Sep 26, 2008 at 10:39 AM, Steve Midgley <science@misuse.org> wrote:
> drop table if exists dummy;
> create table dummy (
>  id integer primary key,
>  name varchar(255),
>  fkey_id integer
>  )
> ;

> The system should return
>
> 502163
> 502164
> 502170
> 502171


--first get all of the duplicated ids
SELECT id    FROM Dummy
GROUP BY name, fkey_id


--Next from this list find check to see if there are any sibling
immediate above or below it.

SELECT A.* FROM ( SELECT ID                 FROM Dummy            GROUP BY name, fkey_id ) AS A
INNER JOIN Dummy AS D             ON A.id - 1 = D.id             OR A.id + 1 = D.id;

-- 
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug


pgsql-sql by date:

Previous
From: Steve Midgley
Date:
Subject: Finding sequential records
Next
From: "Oliveiros Cristina"
Date:
Subject: Re: Finding sequential records