Re: [SQL] selecting newer rows

From: José Soares <jose(at)sferacarta(dot)com>
To: Carlos Henrique Righetto Moreira <righetto(at)isnet(dot)com(dot)br>, sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: [SQL] selecting newer rows
Date: 1999-08-23 13:15:10
Message-ID: 37C1495E.E9AF4D8F@sferacarta.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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é

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Dr. Nisai Wanakule 1999-08-23 13:27:08 Re: [SQL] is this possible, maybe a todo ? function related
Previous Message Herouth Maoz 1999-08-22 12:44:37 Re: [SQL] Counting the number of distinct rows returned