How to write Query on the Result Set of Another Query

  • Hai Every One. Can Any body help me Please.

    I Want to Write a Query On the Result Set Of Another Query.

    How to Write

    Can Any body help me Please.

  • You mean something like this:

    SELECT * FROM

    (SELECT * FROM myTable WHERE col = 'A') tmp;

    Subquery Fundamentals

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Maybe something like this

    with cte (ID, somefield) as

    (

    select ID, FieldName from TableA

    )

    select TableB.Field

    from TableB

    join cte

    on cte.ID = TableB.ID

  • perireddy.arikatla (10/10/2013)


    Hai Every One. Can Any body help me Please.

    I Want to Write a Query On the Result Set Of Another Query.

    How to Write

    Can Any body help me Please.

    There are a lot of ways to do this. Koen's code demonstrates a "Derived Table". There are other methods, as well.

    CTE

    Derived Tables (Sub-queries)

    Correlated Sub-Queries

    Views

    Inline Table Valued Functions

    APPLY (CROSS or OUTER)

    Temp Tables

    INSERT/EXEC

    OpenRowSet

    OpenDataSource

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • As Jeff showed there are many ways to do this. I only provided one possibility.

    I've been a silent observer on this site for along time and finally feel that I have some knowledge to begin offering solutions to some questions. 🙂

  • lrosini (10/11/2013)


    As Jeff showed there are many ways to do this. I only provided one possibility.

    I've been a silent observer on this site for along time and finally feel that I have some knowledge to begin offering solutions to some questions. 🙂

    Ver y cool. Welcome to the fun. 🙂

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply