July 14, 2010 at 4:40 am
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
July 14, 2010 at 4:51 am
Can you specify what the relationship is between the data in the rows ?
July 14, 2010 at 5:00 am
/*
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
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