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 / suraj

-- create table #Employees (EID int, EName varchar(20), MID
int)
-- insert #Employees values(101,'Rama',NULL)
-- insert #Employees values(102,'Sita',101)
-- insert #Employees values(103,'Shiva',101)
-- insert #Employees values(104,'Ganesh',103)

--for 103 ID the manager ID is 101(RAMA) and for 104
manager is SIVA
--Write a script which displays Shiva's Manager's name.

select a.EID, a.EName, a.MID, b.EName
from #Employees a
inner join #Employees b on a.mid=b.eid and a.EName='Shiva'

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the differences between decimal and float in ms sql server?

558


What is the difference between value type and reference type?

549


Explain sub-query?

563


Explain something about security and SQL Azure?

88


Is sql server implemented as a service or an application? : Sql server database administration

507






What are security principals used in sql server 2005?

509


What extended events?

538


you want to be sure that queries in a database always execute at the maximum possible speed. To achieve this goal you have created various indexes on tables which other statement will keep the database in good condition? : Sql server administration

548


What action plan is preferred if sql server is not responding?

529


You schedule a job to run every minute what will happen if the first job runs more than 1 min? Will the second instance of the job start?

576


Explain relational data?

539


How to delete a login name in ms sql server?

524


When would you use a before or after trigger?

486


What is difference between view and materialized view?

531


Mention the command used to rename the database.

532