Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1so2bZ-007qtr-Em for pgsql-general@arkaria.postgresql.org; Tue, 10 Sep 2024 15:16:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1so2bZ-00Ebzz-3i for pgsql-general@arkaria.postgresql.org; Tue, 10 Sep 2024 15:16:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1so2bY-00EbyQ-OA for pgsql-general@lists.postgresql.org; Tue, 10 Sep 2024 15:16:32 +0000 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1so2bU-000UMW-H8 for pgsql-general@postgresql.org; Tue, 10 Sep 2024 15:16:32 +0000 Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-70943713472so2583832a34.2 for ; Tue, 10 Sep 2024 08:16:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725981388; x=1726586188; darn=postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=zRCyrNBDsBi0QBMgj77qmZnPzSV2Og6DDxsOsBLSV9E=; b=Ty8/9FVXgcyGi5McI7dU1kMUwKaIlHBKM5xoFIgBun3ol+uEPia3pyhnCpiPVZZdBi ZUkcipX+lfEjy+SUNbKSAb9TuDVlqe7hgqSTGaf8KptSH/A4z/GGmDHobUREoY3+5nf4 A88OorWRL+I23LOVolzeg5Pt2N+NCO7buEJXyftB/bdKAw3SCiudWRWE79zakIcqvG6B M4YFiCGHs4h1eeW2+jxhc4px8XHlbNCLOWgJV/wvUHa5wWwieeVn4DiqUSDwPIieMTaJ B6lqdCo2Gu1q+9A7YzeOBJCl7kytIOekvY0js+as8I5IgR86tvUcim08svM7vX7KiEjA G4zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725981388; x=1726586188; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zRCyrNBDsBi0QBMgj77qmZnPzSV2Og6DDxsOsBLSV9E=; b=gANT2uhEImR06aTvYSsS0zQCeW7la/oLhjhqGKiXhL/SxZ8xbp/4cAwtpALHt4gjYY vuIyInFsdxZs34urBMQGM/2Ftr+rCieYQ9xwaP7bd+/Xb26UxBwUPnWQQiSkMm5ro7Ae 8wI1ln7A5PGxFULCu4DEqzTeWRXNNiXhNBy86C/1ir9OLs7wCDcXOEPrP5y/djERb5Wv 7PMSU/kI3UvjwN+68aw6PxMvWRLyFqcvH30c7vIt/7133sG6tAlGmzcxW0bbS7LjJx1o g6cs3imntnHsNmKNaQRzEYzZc/t2p2Rv6JgTdmIKATJf7fj2i7knA8T9H0+7fh+AaXWn UF4A== X-Gm-Message-State: AOJu0YwM8su6i2IkKOGxj8XupkdT+XqI7hk0cpYCJ59ityYun+grgI1d Dhl2vqxEcId3hbcugduW9GmkVDsyxVouB6KJR7WOqGFHV1dP7uxC1KULsz/wv3PPypClrm13oHn s6JPcSDhZptQFPnnO3ryJ+F+EXTMkXYki X-Google-Smtp-Source: AGHT+IFpN3gJqRbl9NsnKvPhmJGpF8HacOoBTKp+8pUwf/nDlO/UxqmdwFeDgxwYWkfnfOyt0eoV7u/zb7l+BDzQEvg= X-Received: by 2002:a05:6808:f10:b0:3e0:4057:6dec with SMTP id 5614622812f47-3e040577081mr5836397b6e.2.1725981387594; Tue, 10 Sep 2024 08:16:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ron Johnson Date: Tue, 10 Sep 2024 11:16:15 -0400 Message-ID: Subject: Re: Removing duplicate rows in table To: pgsql-general Content-Type: multipart/alternative; boundary="0000000000007f28130621c55b3b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000007f28130621c55b3b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Sep 10, 2024 at 11:07=E2=80=AFAM Rich Shepard wrote: > I've no idea how I entered multiple, identical rows in a table but I want > to > delete all but one of these rows. > > Here's an example: > > bustrac=3D# select * from projects where proj_nbr =3D '4242.01'; > proj_nbr | proj_name | start_date | end_date | description | > notes > > ----------+----------------+------------+------------+---------------+---= ---- > 4242.01 | Expert witness | 2008-10-15 | 2008-10-28 | Consol Energy | > 4242.01 | Expert witness | 2008-10-15 | 2008-10-28 | Consol Energy | > 4242.01 | Expert witness | 2008-10-15 | 2008-10-28 | Consol Energy | > 4242.01 | Expert witness | 2008-10-15 | 2008-10-28 | Consol Energy | > (4 rows) > > How do I clean this up so there's only a single row for this project > number? > https://www.postgresqltutorial.com/postgresql-window-function/postgresql-ro= w_number/ I'd use row_number to delete records where row_number > 1. --=20 Death to America, and butter sauce. Iraq lobster! --0000000000007f28130621c55b3b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Tue, Sep 10, 2024 at 11:07=E2=80=AFAM = Rich Shepard <rshepard@appl-= ecosys.com> wrote:
I've no idea how I entered multipl= e, identical rows in a table but I want to
delete all but one of these rows.

Here's an example:

bustrac=3D# select * from projects where proj_nbr =3D '4242.01'; =C2=A0 proj_nbr |=C2=A0 =C2=A0proj_name=C2=A0 =C2=A0 | start_date |=C2=A0 e= nd_date=C2=A0 |=C2=A0 description=C2=A0 | notes
----------+----------------+------------+------------+---------------+-----= --
=C2=A0 4242.01=C2=A0 | Expert witness | 2008-10-15 | 2008-10-28 | Consol En= ergy |
=C2=A0 4242.01=C2=A0 | Expert witness | 2008-10-15 | 2008-10-28 | Consol En= ergy |
=C2=A0 4242.01=C2=A0 | Expert witness | 2008-10-15 | 2008-10-28 | Consol En= ergy |
=C2=A0 4242.01=C2=A0 | Expert witness | 2008-10-15 | 2008-10-28 | Consol En= ergy |
(4 rows)

How do I clean this up so there's only a single row for this project nu= mber?


--
Death to America, and butter sauce.
Iraq lobster!
--0000000000007f28130621c55b3b--