Search Postgresql Archives

Finding duplicates only.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux