Sunday, June 8, 2008

Re: [SQL] Need some magic with alternative rows

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


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

No comments: