Solved

Sql - Which employees does not have the required competencies

Posted on 2012-03-30
5
212 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

777 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