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

Need some magic with alternative rows

From: Andreas <maps(dot)on(at)gmx(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Need some magic with alternative rows
Date: 2008-06-07 03:04:05
Message-ID: 4849FAA5.3080309@gmx.net (view raw or flat)
Thread:
Lists: pgsql-sql
Hi,
I need some magic with alternative rows.

I've got a table with rows relating another table.
mytab (id, name, group_nr, class_nr, fk)

SELECT * FROM mytab
WHERE  (fk = 994010)  
      OR   ((class_fk = 40) AND (fk = 0))

994001,   Tick,         1,   40,   994010
4001,      Reporting,   1,   40,   0
4002,       LEADS,     2,   40,   0
994003,   Track,      3,    40,  994010
4003,      Details,      3,  40,   0

The rows with fk=0 are defaults that should only be used when there is 
no specific reference to the other table.

Is there a way to remove the default-rows if there exists a fk<>0 row 
that has the same group_nr ?
I'd like to get just:

994001,   Tick,        1,   40,   994010
4002,       LEADS,   2,   40,   0
994003,   Track,      3,   40,  994010


Regards
Andreas


Responses

pgsql-sql by date

Next:From: Niklas JohanssonDate: 2008-06-08 09:59:22
Subject: Re: Need some magic with alternative rows
Previous:From: Tom LaneDate: 2008-06-07 00:12:07
Subject: Re: crosstab functions in postgres 8.1

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