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
Name the different type of indexes in sql?
Is it possible to have clustered index on separate drive from original table location?
How check triggers in sql server?
Explain nested stored procedure. Syntax and an example for create nested stored procedure?
Define the one-to-one relationship while designing tables.
What are the types of containers in ssis?
What does it mean if @@cursor_row returns a negative number?
What is data modeling and Reterminal integrity?
How each E-R model constructs can be mapped to the relational model?
What are the acid properties?
What do you mean by 'normalization'?
How sql server executes a statement with nested subqueries?
Which are the two editions in which SQL Azure database available?
Why it is recommended to avoid referencing a floating point column in the where clause?
When columns are added to existing tables, what do they initially contain?