Parent Child Relationship

  • Hi,

    I have two queries, say for example

    Select distinct 0 parent_id, ROW_NUMBER() OVER(

    ORDER BY Column2_Desc ) AS 'ID', Column2_Desc

    From table1

    Union

    Select distinct 0 parent_id, ROW_NUMBER() OVER(

    ORDER BY Column2_Desc ) AS 'ID', Column2_Desc

    From table2

    I don’t have relationship between two tables.But I want to frame parent child relationship between these two so that my resultset should like

    Parent_id id Column2_Desc

    0 1 ABC

    0 2 XYZ

    0 3 ASDF

    1 4 VGTY

    2 5 DFT

    I don’t want to use stored procedure.

    Kindly Help Me Out

  • brindaam (12/13/2010)


    Hi,

    I have two queries, say for example

    Select distinct 0 parent_id, ROW_NUMBER() OVER(

    ORDER BY Column2_Desc ) AS 'ID', Column2_Desc

    From table1

    Union

    Select distinct 0 parent_id, ROW_NUMBER() OVER(

    ORDER BY Column2_Desc ) AS 'ID', Column2_Desc

    From table2

    I don’t have relationship between two tables.But I want to frame parent child relationship between these two so that my resultset should like

    Parent_id id Column2_Desc

    0 1 ABC

    0 2 XYZ

    0 3 ASDF

    1 4 VGTY

    2 5 DFT

    I don’t want to use stored procedure.

    Kindly Help Me Out

    I know this post is almost a week old but if you don't have an answer yet, try reading the article at the first post in my signature line below... it'll help you get an answer.

    --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 2 posts - 1 through 1 (of 1 total)

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