I'm having the schemas like:
Employee (Empno, Empname, City)
Project (Pno, Pname)
Part (Partno, Partname, Color)
Use (Pno, Partno)
Works (Empno, Pno)
From these schemas I had created a sample tables:
The goal is to find the names of the projects where no employees are working whose name starts with 'S'
I'm using ORACLE 11g Express Edition. Here I used this query : For Names:
Select DISTINCT Pname FROM
(
SELECT w.Empno, p.Pno, p.Pname, e.Empname
FROM Works w
LEFT JOIN Project p ON w.Pno=p.Pno
LEFT JOIN Employee e ON e.Empno=w.Empno
)
WHERE Empname not like 'S%';
CodePudding user response:
If you think about how to explain the process. There are several methods to solve this including:
- You would start with each of the
Projectsand find out if there does not exist anybody whoWorkson the project where theEmployeesname starts withS. You can do this usingNOT EXISTS.
or
- Again, start with a
Projectand find, if any, whoWorkson the project and their correspondingEmployeesdetails usingLEFT OUTER JOINs (but starting from theProject) and filtering for employee names starting withSin theJOINcondition. ThenGROUP BYthe primary key for the project and find those projectsHAVINGaCOUNTof zero matched employees.
Since this appears to be a homework question, I'll leave the rest for you to complete.
