Output of two queries in single row having complex relationship [message #358773] |
Wed, 12 November 2008 07:57 |
VIVEKSHANKARS
Messages: 6 Registered: October 2008
|
Junior Member |
|
|
I have three tables with the relation mentioned below.
[Table with values uploaded]
Query1
Select b from (Select count(*) b from T1, T2 where T1.A = T2.X and T2.Y = ?) where b>0;
? => a value from table T3 in column L
Select T3.J, T3.K, T3.L from T3 where T3.K='K12'
I need the output in the following format using a single query
T3.J T3.K T3.L b
All the above relations hold good
Ie., T2.X contains values present in T1.A
T3.L contains values present in T2.Y
Can anyone help plzzz....
-
Attachment: Tables.txt
(Size: 0.37KB, Downloaded 585 times)
|
|
|
|
|
|
Re: Output of two queries in single row having complex relationship [message #358943 is a reply to message #358773] |
Thu, 13 November 2008 00:55 |
danish_fsd@yahoo.com
Messages: 38 Registered: February 2008 Location: Pakistan
|
Member |
|
|
Hi,
Here is two solution, i think 2nd is more appropriate.
1st
select * from
(Select T3.J, T3.K, T3.L from T3 where T3.K='k11') a,
(Select b from (Select count(*) b from t1, t2 where T1.A = T2.X and T2.Y = 'y11')
where b>0) b
2nd
Select t3.j, t3.k, t3.l, count(*) b from t1, t2, t3
where T1.A = T2.X
and t2.y=t3.l
and T2.Y = (select l from t3 where t3.k='k11')
group by t3.j, t3.k, t3.l
Regards
Danish
|
|
|
|