Hi all,
i have a table as follows
empid empname mgrid deptid
1 a 3 4
2 b 1 5
3 c 2 3
4 d 3 6
5 e 4 7
i want the output as
empname mgrname
a c
b a
c b
d c
e d
Answers were Sorted based on User's Feedback
Answer / gunturajesh
select a.empname empname,b.empname mgrname from emp a,emp b
where a.mgrid=b.empid
| Is This Answer Correct ? | 20 Yes | 2 No |
Answer / suresh babu
select t1.empname,t2.empname from emp t1,emp t2 where
t1.mgrid = t2.empid;
This query is self join,Which is display your requirement.
| Is This Answer Correct ? | 4 Yes | 0 No |
Answer / alok narayan
1.
select empname,(select empname from e1 b
where b.empid =a.mgrid) from e1 a;
2.
select a.empname empname,b.empname mgrname from e1 a,e1 b
where a.mgrid=b.empid order by a.empname ;
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / nanne saheb c
select e.empname,m.ename mgrname from emp e,emp m
where e.mgrid=m.empid;
| Is This Answer Correct ? | 0 Yes | 0 No |
what is unique key constraint? : Sql dba
What is difference between hql and sql?
Is vs as in pl sql?
How do I clear the screen in sql plus?
What sql does db2 use?
How many types of primary keys are there?
What are data types in pl sql?
How to find the count of letter "L" in HELLO
Can a key be both primary and foreign?
Why are indexes and views important to an organization?
What is a .db file?
What are the various restrictions imposed on view in terms of dml?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)