Odp: SQL Question
Date: Tue, 16 Jan 2001 14:18:41 +0100
Message-ID: <941i6d$72p$1_at_kujawiak.man.lodz.pl>
U¿ytkownik Adrian Ting <adrianting_at_post1.com> w wiadomo¶ci do grup
dyskusyjnych napisa³:941fbe$pic$1_at_dahlia.singnet.com.sg...
> Hi SQL experts, have a SQL question for yer.
>
> 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 ?
>
>
Try this:
SELECT NAME
FROM EMPOLOYEE
WHERE DEPARTAMENTID = 'SALES'
UNION ALL
SELECT NAME
FROM EMPOLOYEE
WHERE NOT EXISTS(SELECT 1 FROM EMPOLOYEE WHERE DEPARTAMENTID = 'SALES');
Received on Tue Jan 16 2001 - 14:18:41 CET