Re: Finding sequential records

From: "Richard Broersma" <richard(dot)broersma(at)gmail(dot)com>
To: "Steve Midgley" <science(at)misuse(dot)org>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Finding sequential records
Date: 2008-09-26 18:02:25
Message-ID: 396486430809261102j73869b8es6b325621bcfe1ea6@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, Sep 26, 2008 at 10:39 AM, Steve Midgley <science(at)misuse(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Oliveiros Cristina 2008-09-26 18:09:24 Re: Finding sequential records
Previous Message Steve Midgley 2008-09-26 17:39:13 Finding sequential records