Re: Need some magic with alternative rows

From: Niklas Johansson <spot(at)tele2(dot)se>
To: Andreas <maps(dot)on(at)gmx(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Need some magic with alternative rows
Date: 2008-06-08 09:59:22
Message-ID: 99DA5C8C-F1D5-42BC-8416-5B91C72269D0@tele2.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On 7 jun 2008, at 05.04, Andreas wrote:
> Is there a way to remove the default-rows if there exists a fk<>0
> row that has the same group_nr ?

Yes, use a correlated sub-query:

SELECT * FROM mytab m1
WHERE fk = 994010 OR (class_nr = 40 AND fk = 0 AND NOT EXISTS (SELECT
1 FROM mytab m2 WHERE m2.group_nr=m1.group_nr AND fk <> 0));

Sincerely,

Niklas Johansson

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Andrei 2008-06-09 08:29:58 Parallel updates on multiple cores
Previous Message Andreas 2008-06-07 03:04:05 Need some magic with alternative rows