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
What are the differences between decimal and float in ms sql server?
What is the difference between value type and reference type?
Explain sub-query?
Explain something about security and SQL Azure?
Is sql server implemented as a service or an application? : Sql server database administration
What are security principals used in sql server 2005?
What extended events?
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
What action plan is preferred if sql server is not responding?
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?
Explain relational data?
How to delete a login name in ms sql server?
When would you use a before or after trigger?
What is difference between view and materialized view?
Mention the command used to rename the database.