Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Mar 01, 2012 12:34 AM by tim.robson
Member
93 Points
70 Posts
Feb 29, 2012 06:32 PM|LINK
Hi,
1.Select A.a,A.b,A.c,B.d,B.e from A,B where A.z = B.a
2.Select C.f,C.g from A,C where A.a = C.a AND C.a in not NULL(or some condition))(this will give multiple values for each value of a in A)
The problem is i need to combine these two queries containing the columns as specified above in select statements,
The result should be something like:
1 2 3 4 5 6 7
1 2 3 4 5 8 9
1 2 3 4 5 0 0
Please help me in how to deal with this kind of situation.
162 Points
54 Posts
Mar 01, 2012 12:34 AM|LINK
Use the technique called "correlated subquery" to get the result you want. You can search online for more info about correlated subquery.
The query will look like:
Select A.a,A.b,A.c,B.d,B.e, D.f, D.g
from A,B, (
SELECT C.f,C.g from A,C where A.a = C.a AND C.a
) as D
where A.z = B.a
I did not compile or execute the SQL, but your final SQL should look like mine.
Hope it helps.
------------------------------------------------
Tim Robson, MCSD, MCDBA
Comm100, Live Chat Software Provider
karthik_newb...
Member
93 Points
70 Posts
Building select query
Feb 29, 2012 06:32 PM|LINK
Hi,
1.Select A.a,A.b,A.c,B.d,B.e from A,B where A.z = B.a
2.Select C.f,C.g from A,C where A.a = C.a AND C.a in not NULL(or some condition))(this will give multiple values for each value of a in A)
The problem is i need to combine these two queries containing the columns as specified above in select statements,
The result should be something like:
1 2 3 4 5 6 7
1 2 3 4 5 8 9
1 2 3 4 5 0 0
Please help me in how to deal with this kind of situation.
tim.robson
Member
162 Points
54 Posts
Re: Building select query
Mar 01, 2012 12:34 AM|LINK
Use the technique called "correlated subquery" to get the result you want. You can search online for more info about correlated subquery.
The query will look like:
Select A.a,A.b,A.c,B.d,B.e, D.f, D.g
from A,B, (
SELECT C.f,C.g from A,C where A.a = C.a AND C.a
) as D
where A.z = B.a
I did not compile or execute the SQL, but your final SQL should look like mine.
Hope it helps.
------------------------------------------------
Tim Robson, MCSD, MCDBA
Comm100, Live Chat Software Provider