Re: SQL for Deleting all duplicate entries

From: brian <brian(at)zijn-digital(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL for Deleting all duplicate entries
Date: 2007-09-10 00:49:22
Message-ID: 46E49492.5090802@zijn-digital.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Håkan Jacobsson wrote:
> Thanx Merlin, have a nice one (vacation)!
>
> It turns out I have'nt described the problem accurately=(
> Data may actually differ in two of the columns (the varchar
> columns).
> I still want to remove rows which share the same data in those
> two columns and have the date column
> set to NULL.
> I.e. row 1,2,3 have:
> column1 = 'foo', column2 = 'hey' and the date column =
> NULL
> row 4,5,6 have:
> column1 = 'brat', column2 = 'yo' and the date column =
> NULL
> I want to keep just one of the 1 - 3 rows and one of the 4 - 6
> rows..
>
> I will try Merlins and Scotts solutions tomorrow. Anyone know
> if I need to modify Merlins and/or Scotts
> solutions to solve this new situation?
>

If i understand correctly, this should give you the records you want to
keep:

SELECT DISTINCT ON (t.one, t.two) t.one, t.two, t.three, [t.n] FROM foo
AS t;

Put those into a tmp table, truncate the original, then put the saved
rows back in.

brian

In response to

Browse pgsql-general by date

  From Date Subject
Next Message novnov 2007-09-10 03:29:43 Time Zone design issues
Previous Message Andrew Maclean 2007-09-09 23:37:04 Re: replacing Access/ Approach etc