Solved

SQL help doing query inside select

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
insert query with value having 's 2 47
how many extra RAM for SQL server is needed 22 35
How to query LOCK_ESCALATION 4 40
Grid querry results 41 74
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now