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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Except error?

Status
Not open for further replies.

Aedahn

IS-IT--Management
Joined
May 19, 2009
Messages
3
Location
US
I am trying to find the logical error behind an example of a database in one of my textbooks, and I am completely stumped on what the issue may be. I've tried researching it and everything. Maybe if someone else could see the problem, I'd appreciate the help.

Find the last names of the employees who do not work in the research department.

(SELECT LNAME FROM EMPLOYEE )
EXCEPT
(SELECT LNAME FROM EMPLOYEE, DEPARTMENT
WHERE EMPLOYEE,DNO = DEPARTMENT.DNUMBER AND DNAME LIKE 'Research');

The site in which the information is from is
 
Why not simply this ?
SELECT E.LNAME
FROM EMPLOYEE E LEFT JOIN DEPARTMENT D ON E.DNO = D.DNUMBER
WHERE D.DNAME = 'Research' OR D.DNAME IS NULL

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OOps, sorry for the typo:
SELECT E.LNAME
FROM EMPLOYEE E LEFT JOIN DEPARTMENT D ON E.DNO = D.DNUMBER
WHERE D.DNAME <> 'Research' OR D.DNAME IS NULL

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That is quite helpful thank you, and that will work fine. I appreciate the help. The only other thing I would ask is whether or not you would know why it is that the previous coding won't work, or what I would be able to do including the EXCEPT. Unfortunately I have to keep the the EXCEPT included in the coding =/
 
why it is that the previous coding won't work
Because JetSQL don't recognize the EXCEPT instruction.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Alright, I appreciate the help you've given, thanks a lot.
 
If you don't like JOIN you may use IN:
SELECT LNAME
FROM EMPLOYEE
WHERE DNO NOT IN(SELECT D.DNUMBER FROM DEPARTMENT WHERE D.DNAME='Research')

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top