From: | Greenhorn <user(dot)postgresql(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Finding duplicates only. |
Date: | 2010-03-11 02:36:34 |
Message-ID: | ddcb1c341003101836j3c9f0175pbe70e9bd5b97f39b@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Merlin Moncure | 2010-03-11 02:56:26 | Re: crosstab functionality for postgres 8.1.4 |
Previous Message | jgirvin | 2010-03-11 01:54:04 | dst question |