473,831 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Impossible SQL problem!

67 New Member
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 1574
Stewart Ross
2,545 Recognized Expert Moderator Specialist
...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
Coolboy55
67 New Member
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 Recognized Expert Specialist
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 Recognized Expert Specialist
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
Coolboy55
67 New Member
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 Recognized Expert Specialist
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
1440
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 getY() of the class Animale from the class Leone, the compiler return to me the same errors. These are the errors: c:\Documents and Settings\Angelo\Documenti\Visual Studio Projects\Savana\Leone.cpp(36) : error C2248: "Animale::x": impossible to...
7
3591
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 you cannot define a static data member of a template class if it ONLY has a default-initializer...
27
1923
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 work for a large University. I wrote a Windows-based database application for my department that is used in purchasing. The University has just released Web-base application that does the same thing using a sub set of the data that my application...
0
1051
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 only use the this indexer for one parametrized parameter. If this is true, anyone knows if this limitation has been lifted in 2.0? It also appears to be a bug in the proxy that marshals calls to the COM interface is unable to call...
3
2690
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" listing in my address book and (optionally) their name listed on my "news" page of my birtle.com website (listed as "Jane Smith is a Programming GOD") for at least a month. Why not take a moment to read more and possibly boost your ego to all time...
5
2445
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 somebody enters part_no, than using Javascript is it possible to connect to the part master and retrieve the division and desc information? I am not allowed to use the PHP because this will require the user to insert the part number on the first...
2
1200
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. There is no attribute "name". <form name="form1" method="post" action="Default.aspx" id="form1"> And input is not allowed here Since ASP.NET buttons should be placed in server side forms, I don't know how to remove this error. So, what this...
3
1720
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 program, and an array won't work. I need to read over a file and store certain information in a struct (person dave; dave.money=200 etc.). However, to stay true to the spec I shouldn't assume that there will always be x many entries I need to store....
1
1166
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 cannot find the element, because it's executed client-side before the control is rendered. If I try it in the control's render, the header has already been rendered, so the script never makes it to the client. Emitting the initialization directly...
5
1022
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 this can't be avoided for now. Meanwhile, my Motorcycle class instantiated a Car as well. Then I moved the Car and Motorcycle classes into separate files. Each imported the Vehicle module.
0
9794
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10538
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5622
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5788
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4419
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3077
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.