Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query help.

Author  Topic 

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2012-01-31 : 03:05:32
I have a below table

Create Table Employee
(
ID int,
Names varchar(40),
Manager_ID int,
Manager_name varchar(40))

--------------------------------------------------
insert into Employee values( 101,'A',110,'B')
insert into Employee values( 110,'X',117,'Y')
insert into Employee values( 117,'M',121,'N')
insert into Employee values( 110,'E',131,'F')
insert into Employee values( 116,'O',117,'P')

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


select * from Employee


ID Names Manager_ID Manager_name
101 A 110 B
110 X 117 Y
117 M 121 N
110 E 131 F
116 O 117 P

I need an output of
110
117
121
131

I need to fetch all the records of dependent from both the column

I tried this but no luck

select a.id from Employee a
join Employee b on a.id=b.manager_ID





Thanks,
Gangadhara MS
SQL Developer and DBA

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-01-31 : 04:41:39
[code]select distinct manager_id from employee[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2012-01-31 : 20:49:45
No actually i need dependent value for the input column ID value.


Thanks,
Gangadhara MS
SQL Developer and DBA
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-01-31 : 21:11:04
what do you mean ? can you explain further ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -