Name,Name1 --Name1,Name2

  • All,

    I have one scenario.

    create table emp

    (

    eno int,

    ename varchar(20),

    designation varchar(20),

    report_to int

    )

    insert into emp values (1000,'Sriram','STE',100)

    insert into emp values (100,'Thiru','PL',10)

    insert into emp values (10,'Hari','PM',5)

    insert into emp values (5,'KSS','FM',1)

    i need result like

    ------------------------------

    sriram Thiru

    Thiru Hari

    Hari KSS

    ----------------

    karthik

  • Can you specify what the relationship is between the data in the rows ?



    Clear Sky SQL
    My Blog[/url]

  • /*

    i need result like

    ------------------------------

    sriram Thiru

    Thiru Hari

    Hari KSS

    ----------------

    */

    DROP table #emp

    create table #emp

    (

    eno int,

    ename varchar(20),

    designation varchar(20),

    report_to int

    )

    insert into #emp values (1000,'Sriram','STE',100)

    insert into #emp values (100,'Thiru','PL',10)

    insert into #emp values (10,'Hari','PM',5)

    insert into #emp values (5,'KSS','FM',1)

    SELECT e1.ename, e2.ename

    FROM #emp e1

    INNER JOIN #emp e2 ON e2.eno = e1.report_to

    ChrisM

    Junior Software Engineer

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

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

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