Solved

Sql - Which employees does not have the required competencies

Posted on 2012-03-30
5
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

726 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