?
Solved

SQL help doing query inside select

Posted on 2012-04-10
2
Medium Priority
?
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 42

Accepted Solution

by:
dqmq earned 2000 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

752 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