Solved

Sql - Which employees does not have the required competencies

Posted on 2012-03-30
5
189 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
It solves the problem, although i'm not sure about the efficiency of this solution.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now