From: José Soares <jose@sferacarta.com>
To: Carlos Henrique Righetto Moreira <righetto@isnet.com.br>
To: sql <pgsql-sql@postgresql.org>
Subject: Re: [SQL] selecting newer rows
Date: Mon, 23 Aug 1999 15:15:10 +0200
Message-ID: <37C1495E.E9AF4D8F@sferacarta.com> (raw)
References: <00a701beea4f$6b443260$0224a8c0@isnet.com.br>
Carlos Henrique Righetto Moreira ha scritto:
> Hi. Thats my problem:
> I have a table with some fields and a thousand of rows. By a mistake in the
> past someone entered duplicated information (the key field is different).
> I need to select some rows from this table but I just want only the newer
> row from the table in the case that row is duplicated. I made myself clear?
> Anyone can help me?
>
> -carlos
>
> ************
Try this:
---all the data in my table: (note that newer rows have oid greater)
prova=> select oid,* from prova order by nome;
oid|chave|nome
------+-----+--------
500663| 2|Carlos
500667| 20|Carlos
500670| 43|David
500662| 1|Henrique
500665| 10|Henrique
500664| 3|Jose
500666| 30|Jose
500669| 33|Manuel
500668| 31|Miriam
(9 rows)
---only duplicate names:
prova=> select nome from prova group by nome having count(*) > 1;
nome
--------
Carlos
Henrique
Jose
(3 rows)
---and now show the oid to see which row is newer:
prova=> select oid,* from prova where nome in (select nome from prova group by
nome having 1 < count(*) );
ERROR: pull_var_clause: Cannot handle node type 108
oops I think I found a bug :(
any way, you can do this by hand.
For example:
prova=> select oid,* from prova where nome = 'Carlos';
oid|chave|nome
------+-----+------
500663| 2|Carlos
500667| 20|Carlos
(2 rows)
The oid 500667 is newer than 500663
I hope this help.
Boa sorte!
José
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: jose@sferacarta.com, righetto@isnet.com.br
Subject: Re: [SQL] selecting newer rows
In-Reply-To: <37C1495E.E9AF4D8F@sferacarta.com>
References: <00a701beea4f$6b443260$0224a8c0@isnet.com.br> <37C1495E.E9AF4D8F@sferacarta.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox