When asking for help on non-trivial SELECT queries it really helps to tell us the version of PG you are using so that responders know what functionality you can and cannot use. In this case specifically, whether WINDOW (and maybe WITH) clauses available? David J. > -----Original Message----- > From: pgsql-general-owner@xxxxxxxxxxxxxx [mailto:pgsql-general- > owner@xxxxxxxxxxxxxx] On Behalf Of Ivan Sergio Borgonovo > Sent: Monday, May 16, 2011 7:39 PM > To: pgsql-general@xxxxxxxxxxxxxx > Subject: find the greatest, pick it up and group by > > > I'd like to group by idordine, grupposped, idart. > For every row grouped that way, I'd like to pick the greatest of the > q* columns and insert: > idordine, grupposped, idart, name of the greatest(q*) in a new table. > I don't mind if more than one q* column is equal to greatest(q*). It should > pick up one, just one no matter which among the one equal to greatest(q*). > > I think this way works but it hurts my eyes. Any alternative approach? > -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general