Ordered output for referenced columns

  • I have table with the following structure and datacreate table #temp (id int not null, refid int)

    The refid column refers id column but there are no constraint as such till now.

    Suppose the table has data as :-

    id refid

    1 2

    2 NULL

    3 NULL

    4 3

    I want the output as:-

    id refid

    1 2

    2 NULL

    4 3

    3 NULL

  • unless you have a way of telling SQL the order, then you can only order on what you have so that would be the id or the refid.

  • Hi,

    So just to confirm,

    this is a parentt-child hierarchy and you wish to start at leaf nodes and work back to root ?

    What would you expext to happen if the row , (5,2) were added to the data ?



    Clear Sky SQL
    My Blog[/url]

  • Thank you Dave for your reply, if it is 5,2 then it would be aftere 1,2. I think you have rightly pointed it should be like the parent-child query. I'm trying to figure out the query.

    Thanks

    Arun

Viewing 4 posts - 1 through 3 (of 3 total)

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