Search Postgresql Archives

How to delete rows number 2,3,4...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello.

I have a table

create table foo (
a serial,
b int,
c int,
.... more fields ...);

and now I wish to remove for each combination of b and c,  all the
rows except the one with the highest value of a.

For example
a  b  c  other fields
=====
1  5  5 .....
2  5  5 ....
3  2  3  ....
4  2  2  ...
5  5  5  ...

should leave

a  b  c  other fields
=====
3  2  3  ....
4  2  2  ...
5  5  5  ...

is there some clever command for this or will I have to write a
special function that loops through all values of  b and c ?

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux