i have a table emp and columns ename,empno,mgr_id,i need ename,manager name as result i.e employee respective manager.. example
empno ename mgr_id
1 john 3
2 paul 3
3 smith 1
4 kevin 1
5 stewart 2

result has to look like this

ename manager
john smith
paul smith
smith john
kevin john
stewart paul


can u plz help me out in this.....

Answer Posted / karthik

select e1.empno,e1.ename EmpName,e2.ename MgrName from emp e1,emp e2
where e1.mgr_id=e2.ename(+);

select e1.empno,e1.ename EmpName,e2.ename MgrName
from emp e1 left outer join emp e2
where e1.mgr_id=e2.ename;

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is query cache in mysql? : Sql dba

577


What is nested table in pl sql?

554


What are keys in sql?

548


What is the difference between rollback and rollback to statements?

583


How to revise and re-run the last sql command?

649






how can you create an empty table from an existing table? : Sql dba

658


How do I pipe the output of one isql to another?

530


Why schema is used in sql?

516


What are sql objects?

539


What is a stored procedure in sql with example?

604


What is posting?

606


Which are the different character-manipulation functions in sql?

547


What is the starting oracle error number? What is meant by forward declaration in functions?

540


Is mariadb nosql?

583


What is the difference between instead of trigger and after trigger?

511