Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create a view with missing data 1

Status
Not open for further replies.

barnard90

IS-IT--Management
Mar 6, 2005
73
US
Hi
I have an " employee " table with empno, empname , deptno, deptname fields.

However in the employee table , all employees have
deptnos , but not all of them have deptnames

There is a " department_backup " table with deptno and deptname . ( This table is not same as department table )

It does not have all the records in department table ,
but most of them ( about 90 % ).

I need to create view , which fetches empno, empname, deptno, deptname from employee.

In case deptname for an employee does not exist , then that corresponding deptname for a deptno is fetched from the " department_backup " table .

Could some one please suggest a code to create the view

Thanks
 
Code:
select e.empno, 
       e.deptno,
       nvl(d.deptname, db.deptname)
from emp e,
     dept d,
     dept_backup db
where e.deptno = d.deptno(+)
and   e.deptno = db.deptno(+)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top