Finding duplicates only. - Mailing list pgsql-general

From Greenhorn
Subject Finding duplicates only.
Date
Msg-id ddcb1c341003101836j3c9f0175pbe70e9bd5b97f39b@mail.gmail.com
Whole thread Raw
Responses Re: Finding duplicates only.  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
List pgsql-general
Hi,

Can someone please help me with this duplicate query.

I'm trying to:

1.  Return duplicates only. (without including the first valid record), and
2.  Return as duplicate if the difference between a.inspection_time
and b.inspection time is under 5 minutes.

Here's the query string I'm using to retrieve the duplicates but it is
returning every duplicate records.

select a.rego,
a.inspection_date,
a.inspection_time,
count(*) as c
from inspections a
  where
    exists (
        select null
        from inspections b
        where
          a.rego = b.rego
          and a.inspection_date = b.inspection_date
          and a.inspection_time = b.inspection_time
        group by
          b.rego, b.inspection_date, b.inspection_time
        )
and status_id in (0)
group by
  a.rego, a.inspection_date, a.inspection_time

having count(*) > 1

Thanks in advance.

pgsql-general by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: log_statement and syslog severity
Next
From: jgirvin
Date:
Subject: dst question