selecting newer rows

Поиск
Список
Период
Сортировка
Искать

selecting newer rows

От:
"Carlos Henrique Righetto Moreira" <righetto@isnet.com.br>
Дата:
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


Re: [SQL] selecting newer rows

От:
José Soares <jose@sferacarta.com>
Дата:
   

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é
 
 
 

FAQ