Home » RDBMS Server » Server Administration » Selecting values from two tables depending on the condition satisfied from one table...
Selecting values from two tables depending on the condition satisfied from one table... [message #372224] Fri, 19 January 2001 11:52 Go to next message
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 Go to previous message
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
Previous Topic: Re: Ref Cursors and PL
Next Topic: decode in control file
Goto Forum:
  


Current Time: Fri May 17 11:39:23 CDT 2024