Selecting values from two tables depending on the condition satisfied from one table... [message #372224] |
Fri, 19 January 2001 11:52 |
Suma
Messages: 5 Registered: April 2000
|
Junior Member |
|
|
Hi all,
I'm trying to write a query for a situation like below:
I've 3 tables, say T1, T2 & T3.
T1 has only one column with only 2 values 1 and 0.
T2 & T3 has each got a column of date datatype.
So if the value is 1 in T1, then the date from T2 has to be selected depending on one more where clause say lesser than sysdate and if the value is 0 then the data from T3 has to be selected on the similar where condition.
Thanks in advance
Regards,
Suma
|
|
|
Re: Selecting values from two tables depending on the condition satisfied from one table... [message #372225 is a reply to message #372224] |
Fri, 19 January 2001 12:38 |
Madhav Kasojjala
Messages: 42 Registered: November 2000
|
Member |
|
|
Hi Suma,
I do not know about other filter conditions
( relation between t1,t2,t3 tables if any)
other than that you can use decode function to achieve this.
Say T1 has tc1 column with values 0,1;
T2 has t2_dt date column.
T3 has t3_dt date column.
Then
Select a.tc1, decode(a.tc1, 0, b.t2_dt,1,c.t3_dt)
from T1 a,
T2 b,
T3 c
where b.t2_dt <sysdate
and other_where_conditions
union
Select a.tc1, decode(a.tc1, 0, b.t2_dt,1,c.t3_dt)
from T1 a,
T2 b,
T3 c
where c.t3_dt <sysdate
and other_where_conditions
let me know if u have problems
Madhav
|
|
|