is it possible to use one query to another query input

Hi ,

i want to select one product and i wan to pass that product to another query . is that possible ??

1 query return multiple value and the have join 3 tables , Its return the product

i wan to use the product in second query is that possible ??
LVL 20
Sathish David  Kumar NArchitectAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulEE Topic AdvisorCommented:
for Oracle or SQL Server?

do you have any more details? an existing query perhaps?
0
Gerwin Jansen, EE MVETopic Advisor Commented:
Select * from table2 where table2.id in (select id from table1);
0
Alex [***Alex140181***]Software DeveloperCommented:
with sel as
 (select id
    from table1)
select *
  from table2,
       sel
 where table2.id = sel.id;

Open in new window

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Vitor MontalvãoMSSQL Senior EngineerCommented:
Yes, it's possible.
For a better support please post the queries and a sample of data and expected result.
0
BartVxCommented:
Hi dravidnsr,

as already posted, with more info you can get better support, however here are some possible leads that may get you started on finding your own solution (assuming the two queries are in separate stored procs):

Use a table variable to store the result in query 1and pass that table variable to query 2 as a parameter
Use a (global or local) temporary table to store the result in query 1, then select from the temp table in query 2 (dont forget to clean up the temp table
Merge the two stored procedures into one
Define a view for the joins in query 1, make a list of IDs for the resulting records in query one and store them in a comma separated string. Pass this list to query two, parse the IDs out of the string and select records from the view based on the list of IDs.

Kind regards,

Bart.
0
Scott PletcherSenior DBACommented:
Yes.  The common way to do that is to use a derived table, which is a subquery within the main query.

For example:

SELECT x..., derived...
FROM tablex x
INNER JOIN (
    SELECT b.product, ...
    FROM tablea a
    INNER JOIN tableb b ON ...
    INNER JOIN tablec c ON ...
    WHERE ...
) AS derived ON
    derived.product = x.product
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.