How to bring child subquery column values to parent for display [message #293067] |
Thu, 10 January 2008 15:15 |
ashokkum
Messages: 2 Registered: February 2007 Location: India
|
Junior Member |
|
|
Hi
Table1:
SNo Name
---- ----
x1..... A
x2..... B
x3..... C
Table2:
SNo ParentSNo Type
---- ---------- ----
y1.......x1.......1
y2.......x1.......2
y3.......x2.......1
y4.......x3.......2
I would like to retrieve only the following output:
Name Type
---- -----
x1.......1 or 2 (any one)
x2.......1
x3.......2
My query is as below:
select t1.name, t2.type from Table1 t1, Table 2 t2 where
t1.sno = t2.parentsno
and t2.type in (1, 2)
and it retreives the results as like below:
Name Type
---- -----
x1.......1
x1.......2
x2.......1
x3.......2
The second record is not required and one x1 is sufficient as long as the x1 is a type of either 1 or 2
So, I would like to write it using subquery for a better understanding, but not sure how get the columns from the child subquery. i.e.
select name from Table1 where
sno in (select parentsno from Table2 where type in (1, 2))
which gives only:
Name
----
x1
x2
x3
I would like to also retrieve the type along with the name using subquery, can you help?
Thanks,
Ashok
|
|
|
|
|