From: | Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com> |
---|---|
To: | Alexander Farber <alexander(dot)farber(at)gmail(dot)com> |
Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Adding PRIMARY KEY: Table contains duplicated values |
Date: | 2013-02-04 15:29:38 |
Message-ID: | 510FD3E2.8020202@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 02/04/2013 06:45 AM, Alexander Farber wrote:
> Trying to delete the older of the duplicated pairs:
>
> # SELECT id, author, count(1), max(stamp) as maxx
> FROM pref_rep
> GROUP BY id, author
> HAVING count(1) >1 and stamp < maxx;
> ERROR: column "maxx" does not exist
> LINE 4: HAVING count(1) >1 and stamp < maxx;
> ^
Caffeine has not reached critical mass yet, so test before using:
SELECT * FROM pref_rep JOIN (SELECT id, author, count(1) AS ct,
max(stamp) AS maxx FROM pref_rep GROUP BY id,author) max_time ON
max_time.id=pref_rep.id WHERE ct > 1 AND stamp < maxx;
>
--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Edson Richter | 2013-02-04 15:52:07 | Re: Diferences between IN and EXISTS? |
Previous Message | zeljko | 2013-02-04 15:03:53 | Re: Diferences between IN and EXISTS? |