I’m trying to select all Projects which have Employees who are AtWork.
Projects:
ProjName | EmpOnProj
--------------------------
Alpha | 1, 2, 3
Beta | 1, 3
Employees:
EmpID | EmpName | AtWork
-------------------------------------
1 | John | TRUE
2 | Mark | FALSE
3 | Mary | TRUE
I need to output all projects which could currently be worked on; ie, I need to show Beta because the employees working on Beta are at work.
Currently I cannot say “ALL EMPLOYEES MUST BE AT WORK” only the following:
SELECT ProjName FROM Projects INNER JOIN
Employees ON EmpOnProj.Value = EmpID
WHERE AtWork = true
GROUP BY ProjName
which returns both, as it sees one correct employee and displays the project.
I think I solved this one. Basically I’m saying ‘show all projects except those where somebody is NOT at work’
http://sqlfiddle.com/#!3/36c48/2
There may be a simpler solution but this works (or it looks like it anyway) 🙂
Edit: Modified to remove
GROUP BYs as suggested in comments.