Solved

Sql - Which employees does not have the required competencies

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
compare date to getdate() 8 17
Options for Linking SQL tables to Access 2013 9 42
Error 438 6 16
calculate running total 8 16
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…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

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