Solved

SQL help doing query inside select

Posted on 2012-04-10
2
220 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Not selecting duplicate data 6 53
Upgrading SQL 2005 Express to 2008 R2 Express 31 93
Caste datetime 2 57
Urgent help needed! Unable to to paste in query designer 29 43
If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

773 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