Re: Reg: Sql Join - Mailing list pgsql-sql

From David G Johnston
Subject Re: Reg: Sql Join
Date
Msg-id 1406760545580-5813364.post@n5.nabble.com
Whole thread Raw
In response to Re: Reg: Sql Join  (David G Johnston <david.g.johnston@gmail.com>)
List pgsql-sql
David G Johnston wrote
> 
> CrashBandi wrote
>> Hi,
>> 
>> I am having the following question. I am not sure how to approach it.
>> Please help!
>> 
>> table A
>>  name col1 col2 col3 col4  apple 100 11111 1 APL  orange 200 22222 3 ORG
>> carrot 300 33333 3 CRT
>> 
>> table B
>>   custom_name value obj_type obj_id  apple a FR 100  orange o FR 200 
>> carrot
>> c VG 300  apple d FR 11111  orange e VG 22222  carrot f UC 33333  apple h
>> VG
>> 1  orange o FR 3  carrot c VG 3
>> when obj_type ='FR' then join on col1
>> When obj_type='VG' then join on col2
>> When obj_type='UC' then join on col2
>> 
>> Thanks In advance,
>> CB
> You cannot do conditional joins in this manner.  You will need to write
> three joins, one each against a subquery with the appropriate where
> clause.
> 
> David J.

Actually you might be able to do:

On (case obj_type when 'xxx' then col1 when 'yyy' then col2 end = obj_id) 

But I haven't tried something like this before.

David J.




--
View this message in context: http://postgresql.1045698.n5.nabble.com/Reg-Sql-Join-tp5813360p5813364.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.



pgsql-sql by date:

Previous
From: David G Johnston
Date:
Subject: Re: Reg: Sql Join
Next
From: Oliver d'Azevedo Christina
Date:
Subject: Re: Reg: Sql Join