Let it be 1 table "employee" in database, having 3 attributes, "emp_id", "emp_name", "emp_boss".
Employee
emp_id - emp_name - emp_boss
1 - abc - 2
2 - xyz - 2
3 - lmn - 1
4 - pqr - 3
Get employee name and his/her boss name
Let it be 1 table "employee" in database, having 3 attributes, "emp_id", "emp_name", "emp_boss".
Employee
emp_id - emp_name - emp_boss
1 - abc - 2
2 - xyz - 2
3 - lmn - 1
4 - pqr - 3
Get employee name and his/her boss name
Try this
select emp_name,(select emp_name from employee where emp_id=a.emp_id) boss_name from employee a;
You can also try this
This query uses self join.Code:select a.emp_name employee, b.emp_name manager from emp a ,emp b where a.emp_boss=b.empid