Re: conditional FROM - Mailing list pgsql-sql

From David Johnston
Subject Re: conditional FROM
Date
Msg-id 2BBB44CA-7EFA-4084-906F-6CB72AD28C6E@yahoo.com
Whole thread Raw
In response to conditional FROM  (Richard Klingler <richard@klingler.net>)
Responses Re: conditional FROM
List pgsql-sql
On Dec 10, 2011, at 11:03, Richard Klingler <richard@klingler.net> wrote:

> Good day...
> 
> I'm trying to build a query for PGSQL 9.1 where a table has two 
> references with only one being used depending of the type of entry..
> 
> For example, the table has following simplified structure:
> 
>    portid        primary key
>    port2node    index to table node
>    port2card    index to table card
> 
> So how can I do a conditional FROM clause in the query depending on the 
> column port2node and port2card?
> If port2card is Null or 0 I don't want it in the FROM clause as the 
> query will return unneccessary duplicate
> row...the same goes for port2node being Null or 0...
> 
> 
> thanx in advance
> richard
> 
> 

Two options (one of which may not work for you).

1. Write two queries, one for each table, and union the results.
2. Use LEFT JOINs (somehow...)

David J.


pgsql-sql by date:

Previous
From: Andreas Kretschmer
Date:
Subject: Re: conditional FROM
Next
From: Richard Klingler
Date:
Subject: Re: conditional FROM