Solved

SQL help doing query inside select

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
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 tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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