table:employee
EID ENAME MID(manager ids)
101 rama null
102 sita 101
103 siva 101
104 ganesh 103
. . .
. . .
for 103 ID the manager ID is 101(RAMA) and for 104 manager
is SIVA
if i give employee id (EID) you have to tell the manager for
that EID write query?
eample:if i give 102 .The query output should be manager for
102 ID that it should print RAMA as output

Answer Posted / mohana krishna

select ename from employee
where eid = (select case mid when null then aid
else mid end mid
where eid=@aid
)


select m.name from employee e
join employee m on (m.aid=e.mid)

Is This Answer Correct ?    0 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a heap?

609


What is a cursor, index in sql?

567


Can we write a distributed query and get some data which is located on other server and oracle database?

756


Explain the characteristics of a transaction server for example atomicity, consistency, isolation, durability?

509


Explain about sql server login?

587






What are the recovery models in sql server 2000?

550


What is the difference between clustered index and primary key?

498


How to turn on the mssql api module in php?

559


Where does the copy job runs in the log shipping primary or secondary? : sql server database administration

592


 Explain what is sql override for a source taLle in a mapping?

569


What is the difference between set and select?

569


How to download and install microsoft .net framework version 2.0?

542


Which language rdl files made of?

100


How do you check sql server is up and running?

508


What is Service Broker in sql server 2012?

616