Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

simple self join query

DBA_1976Feb 23 2017 — edited Feb 24 2017

Hi,

I am practicing basic SQL skills. I am using hr sample schema. My question is about a simple self join.

1. select count(*)  from employees;   -- returns 107 rows.

2. select first_name, employee_id, manager_id from employees; -- returns 107 rows with Steven, emp_id 100 and Manager_id null. ( because he is the AD_PRES)

Now instead of manager_id from the above sql, I need their name.

So I did a self join,

3. select e.first_name, e.employee_id, m.manager_name from employees e, employees m where e.manager_id = m.employee_id; -- This returns 106 rows with the exception of Steven, emp_id 100. ( I understand why it is not returned, because the manager_id is null for that row).

But I want that row also, with his manager name something like "No Manager". I tried using NVL function. But it is not working. What am I doing wrong? How can I achieve this?

In short I want 107 rows for the third query. How can I do that?

Thanks,

This post has been answered by Ahmed Haroon on Feb 23 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 24 2017
Added on Feb 23 2017
12 comments
1,440 views