473,385 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Impossible SQL problem!

Goal: Select all employees that have all skills necessary to complete a task.

Relevant tables and (fields): Employees (EmployeeID, EmployeeName), Employees/Skills (EmployeeID, SkillID), Tasks/Skills (TaskID, SkillID)

Relevant forms: Tasks

Relevant relationships: Employees to Skills is Many-to-Many, Tasks to Skills is Many-to-Many

Goal restated: Populate combobox TaskCompletedBy on form Tasks with all EmployeeNames from table Employees where [Employees/Skills].[SkillID] is a subset of [Tasks/Skills].[SkillID].

Example: Employee1 has Skill1, Skill2, and Skill3. Task1 requires Skill2 and Skill3. Combobox is populated with Employee1, since his skillset is a subset of the required skillset.

Can anyone help me out? This SQL statement is going to give me a stroke.

CB55
Mar 20 '08 #1
6 1551
Stewart Ross
2,545 Expert Mod 2GB
...Relevant relationships: Employees to Skills is Many-to-Many, Tasks to Skills is Many-to-Many
...
Before you even attempt to write your query you must resolve the table design into a normalised form. Your many-to-many relationships must be resolved - you have no chance of writing anything useful until you do. This means creating link tables that resolve the many-to-many into two one-to-many relationships in each case.

There is a useful article in the HowTo section of the forum: see Database Normalisation and Table Structures.

-Stewart
Mar 20 '08 #2
Before you even attempt to write your query you must resolve the table design into a normalised form. Your many-to-many relationships must be resolved - you have no chance of writing anything useful until you do. This means creating link tables that resolve the many-to-many into two one-to-many relationships in each case.

There is a useful article in the HowTo section of the forum: see Database Normalisation and Table Structures.

-Stewart
Sorry, I was unclear in my original post. I have link tables already with names Employees/Skills and Tasks/Skills with the fields I listed.
Mar 20 '08 #3
FishVal
2,653 Expert 2GB
Hi, there.

Your design is still unclear.
Please post the tables metadata, particulary what concerns relationships.
Here is an example of how to post table MetaData :
Table Name=tblStudent
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. StudentID; AutoNumber; PK
  3. Family; String; FK (table name 1)
  4. Name; String
  5. University; String; FK (table name 2)
  6. Mark; Numeric
  7. LastAttendance; Date/Time
Regards,
Fish
Mar 20 '08 #4
FishVal
2,653 Expert 2GB
Ok.

I think the following may be a solution.
It seems to work, though not thoroughly tested.
The naming is slight not the same, but I guess quite recognizable.

qryEmpSkills
Expand|Select|Wrap|Line Numbers
  1. SELECT tblEmps.keyEmpID, tblEmps.txtEmpName, tblEmpsSkills.keySkillID
  2. FROM tblEmps INNER JOIN tblEmpsSkills ON tblEmps.keyEmpID = tblEmpsSkills.keyEmpID;
  3.  
qryTaskSkills
Expand|Select|Wrap|Line Numbers
  1. SELECT tblTasks.keyTaskID, tblTasks.txtTaskName, tblTasksSkills.keySkillID
  2. FROM tblTasks INNER JOIN tblTasksSkills ON tblTasks.keyTaskID = tblTasksSkills.keyTaskID;
  3.  

And the query doing the job.
Expand|Select|Wrap|Line Numbers
  1. SELECT qryEmpSkills.keyEmpID, qryEmpSkills.txtEmpName
  2. FROM qryEmpSkills RIGHT JOIN qryTaskSkills ON qryEmpSkills.keySkillID = qryTaskSkills.keySkillID
  3. WHERE (((qryTaskSkills.keyTaskID)=<.... required Task ID goes in here ...>))
  4. GROUP BY qryEmpSkills.keyEmpID, qryEmpSkills.txtEmpName
  5. HAVING (((Count(qryEmpSkills.keySkillID))=(SELECT Count(qryTaskSkills.keySkillID) FROM qryTaskSkills WHERE qryTaskSkills.keyTaskID=<.... required Task ID goes in here too ...>)));
  6.  
Regards,
Fish
Mar 20 '08 #5
Ok.

I think the following may be a solution.
It seems to work, though not thoroughly tested.
The naming is slight not the same, but I guess quite recognizable.

qryEmpSkills
Expand|Select|Wrap|Line Numbers
  1. SELECT tblEmps.keyEmpID, tblEmps.txtEmpName, tblEmpsSkills.keySkillID
  2. FROM tblEmps INNER JOIN tblEmpsSkills ON tblEmps.keyEmpID = tblEmpsSkills.keyEmpID;
  3.  
qryTaskSkills
Expand|Select|Wrap|Line Numbers
  1. SELECT tblTasks.keyTaskID, tblTasks.txtTaskName, tblTasksSkills.keySkillID
  2. FROM tblTasks INNER JOIN tblTasksSkills ON tblTasks.keyTaskID = tblTasksSkills.keyTaskID;
  3.  

And the query doing the job.
Expand|Select|Wrap|Line Numbers
  1. SELECT qryEmpSkills.keyEmpID, qryEmpSkills.txtEmpName
  2. FROM qryEmpSkills RIGHT JOIN qryTaskSkills ON qryEmpSkills.keySkillID = qryTaskSkills.keySkillID
  3. WHERE (((qryTaskSkills.keyTaskID)=<.... required Task ID goes in here ...>))
  4. GROUP BY qryEmpSkills.keyEmpID, qryEmpSkills.txtEmpName
  5. HAVING (((Count(qryEmpSkills.keySkillID))=(SELECT Count(qryTaskSkills.keySkillID) FROM qryTaskSkills WHERE qryTaskSkills.keyTaskID=<.... required Task ID goes in here too ...>)));
  6.  
Regards,
Fish
Ahh! Thank you so much! :D It works perfectly! I was trying to pile it all into one query and never even thought to split it up. Even though I phrased my question incorrectly, your solution was the correct one for the right question. I had said that the employee's skillset should be a subset of the required skills for the task, when of course it was the other way around. Here was my solution for the wrong question:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT DISTINCT [Employees].[EmployeeName] FROM Employees INNER JOIN [Employees/Skills] ON [Employees].[EmployeeID]=[Employees/Skills].[EmployeeID] 
  3. WHERE [Employees/Skills].[SkillID] IN (SELECT [Tasks/Skills].[SkillID] FROM [Tasks/Skills] WHERE [TaskID]=[Forms]![Tasks]![SUB - FMEA Tasks]![TaskID])
  4. ORDER BY [Employees].[EmployeeName];
  5.  
  6.  
There probably is a way to write the query in one line, but I'm not going to try. :) Thanks again!

CB55
Mar 20 '08 #6
FishVal
2,653 Expert 2GB
You are welcome.
Good luck.
Mar 20 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Piotre Ugrumov | last post by:
I have tried to modify my exercise about the simulation of the life in the savannah. Now I have only 2 errors but I don't comprehend how resolve these errors. If I try to call the method getX() and...
7
by: Paul | last post by:
Hi, I have a problem with the C++ spec 14.7.3.15 (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14761 for relevant discussion). It seems that the code (below) is impossible to get right, as...
27
by: Greg Smith | last post by:
Hello, I have been given a programming task that falls into the "impossible" category with my current skill set. I am hoping somebody out there knows how to do this and can save my b-t. I...
0
by: Gianluca | last post by:
Is is true that it's impossible to write a C# wrapper for an IDispatch COM object that has more than one property with parameters? I tried everything I could think of and nothing works. You can...
3
by: Brian Birtle | last post by:
**** A CHALLENGE TO THE GURUS - refute the statement "It's impossible to build a file upload progress meter using ASP.NET" **** First person to prove me wrong gets "All Time .NET Programming GOD"...
5
by: ggk517 | last post by:
We are trying to develop an Engineering application using PHP, Javascript with Informix as the back-end. Is it possible to retrieve data using Javascript but by accessing the Database. Say...
2
by: Cat | last post by:
I created a web site, and I thought I followed XHTML 1.1 rules. But when I validated the pages, I got some error messages. I found that those codes are automatically generated parts by ASP.NET. ...
3
by: Prometheum | last post by:
Having read over some of the disscussions involving incrementing variable names in C++, I have the impression that it's impossible. Is that true? I have a very definite need for them in the following...
1
by: PJ6 | last post by:
It is apparently impossible to emit a initialization script (that refers to a specific element) using RegisterClientScriptBlock; if it is emitted OnLoad, the browser throws an exception that it...
5
by: Matthew Wilson | last post by:
I started off with a module that defined a class Vehicle, and then subclasses Car and Motorcycle. In the Car class, for some bizarre reason, I instantiated a Motorcycle. Please pretend that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.