Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> Re: SQL Question
> I have 2 tables -
> EMPLOYEE : EmployeeID,DepartmentID, Name
> and
> DEPARTMENT : DepartmentID, Description
>
> Both DepartmentIDs are related.
>
> I want to retrieve Employee Names with
> EITHER
> - Employee.DepartmentID = 'SALES'
> OR
> ALL Employees
>
> In another word,
> If no employee is found with the department 'SALES', I would want the whole
> list of Employees returned or else only those with department 'SALES' will
> be returned.
>
> Is this possible ?
Not only possible ... it is a very standard bit of SQL known as an outer join. The syntax would be something like this:
SELECT e.employeeID, e.name, d.description
FROM employee e, department d
WHERE e.departmentID = d.departmentID (+)
AND d.departmentID = 'SALES'
The (+) signifying a left outer join in which you retrieve all records from the employee table (aliased "e") and where they exist, the department description where there is a corresponding department table record.
Daniel A. Morgan Received on Tue Jan 16 2001 - 23:40:13 CST
![]() |
![]() |