?
Solved

Sql - Which employees does not have the required competencies

Posted on 2012-03-30
5
Medium Priority
?
271 Views
Last Modified: 2012-04-15
access relations
I have a SQL/Access question that is driving me crazy! In the picure above is a cutout of the raltions in my DB. I would like to ask the DB which employees does not have the required competencys specified by the position they have, but i cant get it to work. I'm at my wits end here and i need help!
0
Comment
Question by:Nazaroth
  • 3
  • 2
5 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 37786081
Try this:

SELECT Employees.ID, LastName, FirstName
FROM ((Employees LEFT JOIN EmployeePosition ON Employees.ID = EmployeePosition.EmplyeeID) LEFT JOIN Positions ON EmployeePosition.PositionID = Positions.ID) LEFT JOIN RequiredCompetencies ON Positions.ID = RequiredCompetencies.PositionID
WHERE RequiredCompetencies.CompetencyID <> [Enter Competency ID]
0
 
LVL 61

Expert Comment

by:mbizup
ID: 37786250
Hmm - or possibly this:

SELECI Employees.ID, FirstName,LastName,Compentencies.Title, Competencies.ID
FROM (Employees LEFT JOIN EmployeeCompetencies ON Employees.ID = EmployeeCompetencies.EmployeeID)  LEFT JOIN Competencies ON EmployeeCompetencies.CompetencyID = Competencies.ID
WHERE Competencies.ID  NOT IN
(SELECT Competencies.ID FROM ((Employees LEFT JOIN EmployeePosition ON Employees.ID = EmployeePosition.EmplyeeID) LEFT JOIN Positions ON EmployeePosition.PositionID = Positions.ID) LEFT JOIN RequiredCompetencies ON Positions.ID = RequiredCompetencies.PositionID)

The first select pulls employees and their competencies.
The second pulls "required competencies" based on employee and position.
The NOT IN  should restrict the employees  pulled overall to those that do not have the "required competencies"
0
 

Author Comment

by:Nazaroth
ID: 37796007
Thank you for your fast reply!

Your answers does not help me though...

The first expression can be translated to "Which employees have this specific competency?" and that is helpful, but not precisely what i hade in mind.

The second expression results in an empty set, and I know for sure that that is not the correct answer. I'v been fiddling with the syntax for several hours today but i cant get it to work..
If I, in the NOT IN select change from CompetencyID to RequiredCompetencies.CompetencyID i get a list of competencies that the employees have but that are not required, but i can't seem to get the opposite!

I should mention that I'm using Access 2010
0
 

Accepted Solution

by:
Nazaroth earned 0 total points
ID: 37827838
I solved it!

All those parenthesis in Access and inner joins confused me so I used implicit join notation instead, which i find more readable in general.

My problem was that i hade to reversed the selection, instead of aksing what employees does not have required competencies I ask what required competencies is not part of the employees competencies for the position he/she is in.

SELECT DISTINCT emp.ID, emp.FullName, Positions.[Titel SWE], Competencies.Title
FROM Employees AS emp, EmployeePosition, Positions, EmployeeCompetencies,RequiredCompetencies, Competencies
WHERE emp.ID=EmployeePosition.EmployeeID
AND EmployeePosition.PositionID=Positions.ID
AND EmployeeCompetencies.EmployeeID=emp.ID
AND RequiredCompetencies.PositionID = EmployeePosition.PositionID
AND Competencies.ID = RequiredCompetencies.CompetencyID
AND RequiredCompetencies.CompetencyID Not In (
SELECT EmployeeCompetencies.CompetencyID
FROM EmployeeCompetencies
WHERE EmployeeCompetencies.EmployeeID = emp.ID);
0
 

Author Closing Comment

by:Nazaroth
ID: 37847964
It solves the problem, although i'm not sure about the efficiency of this solution.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question