Solved

SQL help doing query inside select

Posted on 2012-04-10
2
223 Views
Last Modified: 2012-04-10
I need to modify some TSQL. Current code does something like this:

select c.rs_id
from a_of a, b_of b, c_of c
where a.o_id=b.o_id and a.bstat IN ("X", "Y")

I need to get a.user_id and use it to find c.mkt_ind. How can I modify this to have a query within a query?

I've heavily modified the original code.  This is just the general idea.
0
Comment
Question by:roujesky
2 Comments
 
LVL 42

Accepted Solution

by:
dqmq earned 500 total points
ID: 37828516
I wouldn't describe that as a "query within a query"... simply a join.

Modernize your SQL like this:


select c.rs_id, c.mkt_ind
from a_of a
inner join b_of b on a.o_id=b.o_id
inner join c on a.user_id = c.user_id     <--guessing here, see note below
where a.bstat IN ("X", "Y")

This join clause needs to identify the proper relationship between tables a and c
0
 

Author Closing Comment

by:roujesky
ID: 37829965
thanks!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question