Skip site navigation (1) Skip section navigation (2)

Re: restricting similar rows

From: Ciprian Popovici <ciprian(dot)popovici(at)integrare(dot)ro>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: restricting similar rows
Date: 2002-09-19 10:39:46
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Thursday, September 19, 2002, 12:01:46 PM, Ciprian Popovici <ciprian(dot)popovici(at)integrare(dot)ro> wrote:
> need all of them. Plus I don't know how to properly translate this
> query into Postgres.

Figured it out, eventually. Here's the Postgres query:

select distinct on (code) \
  id,code,active from objects \
  where version<=1 and (process=17 or process=0) \
  group by id,code,active,version \
  order by code asc,active desc,version desc

I supply version and process values and I get whatever I need back
(id,code,active). Kudos to Postgres for the 'distinct on' clause.

-- Ciprian Popovici <ciprian(dot)popovici(at)integrare(dot)ro>

In response to

pgsql-novice by date

Next:From: Rory Campbell-LangeDate: 2002-09-19 14:14:17
Subject: Make an id field max(id)+1 rather than SERIAL
Previous:From: Joel RodriguesDate: 2002-09-19 09:43:39
Subject: Re: 7.2.2 java configure problem on Mac OS X 10.1.5

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group