pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
selecting newer rows
2+ messages / 2 participants
[nested] [flat]

* selecting newer rows
@ 1999-08-19 14:30  Carlos Henrique Righetto Moreira <righetto@isnet.com.br>
  0 siblings, 1 reply; 2+ messages in thread

From: Carlos Henrique Righetto Moreira @ 1999-08-19 14:30 UTC (permalink / raw)
  To: pgsql-sql

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




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [SQL] selecting newer rows
@ 1999-08-23 13:15  José Soares <jose@sferacarta.com>
  parent: Carlos Henrique Righetto Moreira <righetto@isnet.com.br>
  0 siblings, 0 replies; 2+ messages in thread

From: José Soares @ 1999-08-23 13:15 UTC (permalink / raw)
  To: Carlos Henrique Righetto Moreira <righetto@isnet.com.br>; 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é

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~1999-08-23 13:15 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-08-19 14:30 selecting newer rows Carlos Henrique Righetto Moreira <righetto@isnet.com.br>
1999-08-23 13:15 ` José Soares <jose@sferacarta.com>

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