Query for three tables

CELES

Board Regular
Joined
Jan 1, 2006
Messages
81
Hi All,
I have a database and need to create a query that will pull information from 3 tables.
Table Name Description
1 - courses: contains list of courses and their (course) levels
2 - Students: contains list of students and their training levels
3 - TrainingRecord: contains list of courses completed by each student and completion status.

The biggie here is I only want to know which courses a student needs to take based on their training level.

Thanks
 
Last edited:
I'd post a screen shot of the records in Datasheet view, but my database is at home (I'm a work now). I used the March 25th 6:48pm sample data you posted (the set that did NOT have manager first names).

If you want, post a sample database and I'll work with that --- then we'll be certain we have the same data.
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I just saw that posting live samples isn't possible here. You can send me a sample database by clicking on my hyperlink, left, and emailing the database to me. Alternately, you can post it somewhere on the web where I could download it. I only need a few records in each table. Edit any data that might be confidential. I'll look at this weekend.
 
Upvote 0
Well, I might have used the wrong database. I'll try again, if I can't get it I'll email the database to you early morining. Thanks a mil.
 
Upvote 0
I'm trying to send the database through the AccHTLM tool found on this site. Not sure how this works!

<CENTER><TABLE cellSpacing=0 align=center cellpadding=2px width=50% ><TR ><TD CLASS="AccTBMain" border-left=1px solid colSpan= 8 ><TABLE width="100%" align=left VALIGN="TOP" ><TR ><TD CLASS="AccTBInner" align=Left ><A HREF="javascript: void(0)" onclick="myFunc('233837366','TblTrainingRecord : ',' Record Count: 6');" title=" Record Count: 6"><font color="White">TblTrainingRecord : Table</font></A></TD><TD CLASS="AccTBInner" align=right >Access 2000</TD></TR></TABLE></TD></TR><TR ><TD CLASS="AccHDRLeftElem" ><BR></TD><TD CLASS="AccHDRMain" align=left ><A HREF="javascript: void(0)" onclick="myFunc('233837366','RecNumber : ','AutoNumber Primary Key Indexed (No Duplicates) ');" title="AutoNumber Primary Key Indexed (No Duplicates) ">RecNumber</A></TD><TD CLASS="AccHDRMain" align=left ><A HREF="javascript: void(0)" onclick="myFunc('233837366','AttendeeSEID : ','Text(5) Indexed (Duplicates OK) Field Description: F-Key from TblManagers (Lookup Field)');" title="Text(5) Indexed (Duplicates OK) Field Description: F-Key from TblManagers (Lookup Field)">AttendeeSEID</A></TD><TD CLASS="AccHDRMain" align=left ><A HREF="javascript: void(0)" onclick="myFunc('233837366','CourseNumber : ','Text(10) Field Description: F-Key from TblCourseList (Probably will be a lookup field)');" title="Text(10) Field Description: F-Key from TblCourseList (Probably will be a lookup field)">CourseNumber</A></TD><TD CLASS="AccHDRMain" align=left ><A HREF="javascript: void(0)" onclick="myFunc('233837366','FromDate : ','Date/Time ');" title="Date/Time ">FromDate</A></TD><TD CLASS="AccHDRMain" align=left ><A HREF="javascript: void(0)" onclick="myFunc('233837366','ToDate : ','Date/Time ');" title="Date/Time ">ToDate</A></TD><TD CLASS="AccHDRMain" align=left ><A HREF="javascript: void(0)" onclick="myFunc('233837366','Status : ','Text(25) ');" title="Text(25) ">Status</A></TD><TD CLASS="AccHDRMain" align=left ><A HREF="javascript: void(0)" onclick="myFunc('233837366','Notes : ','Text(255) ');" title="Text(255) ">Notes</A></TD></TR><TR ><TD ID="currRec" CLASS="AccHDRLeftElem" ><img src='AccArr.gif' width='7' height='7'/></TD><TD CLASS="AccDataElem" >1</TD><TD CLASS="AccDataElem" >AAAA1</TD><TD CLASS="AccDataElem" >13458</TD><TD CLASS="AccDataElem" >1/2/2009</TD><TD CLASS="AccDataElem" >1/30/2009</TD><TD CLASS="AccDataElem" >Complete</TD><TD CLASS="AccDataElem" ><BR></TD></TR><TR ><TD ID="currRec" CLASS="AccHDRLeftElem" ><BR></TD><TD CLASS="AccDataElem" >2</TD><TD CLASS="AccDataElem" >AAAA1</TD><TD CLASS="AccDataElem" >13466</TD><TD CLASS="AccDataElem" >1/30/2009</TD><TD CLASS="AccDataElem" >2/15/2009</TD><TD CLASS="AccDataElem" >Incomplete</TD><TD CLASS="AccDataElem" ><BR></TD></TR><TR ><TD ID="currRec" CLASS="AccHDRLeftElem" ><BR></TD><TD CLASS="AccDataElem" >3</TD><TD CLASS="AccDataElem" >BBBB1</TD><TD CLASS="AccDataElem" >15341</TD><TD CLASS="AccDataElem" >1/30/2009</TD><TD CLASS="AccDataElem" >2/15/2009</TD><TD CLASS="AccDataElem" >Waived</TD><TD CLASS="AccDataElem" ><BR></TD></TR><TR ><TD ID="currRec" CLASS="AccHDRLeftElem" ><BR></TD><TD CLASS="AccDataElem" >4</TD><TD CLASS="AccDataElem" >BBBB1</TD><TD CLASS="AccDataElem" >15344</TD><TD CLASS="AccDataElem" >2/2/2009</TD><TD CLASS="AccDataElem" >2/19/2009</TD><TD CLASS="AccDataElem" >Complete</TD><TD CLASS="AccDataElem" ><BR></TD></TR><TR ><TD ID="currRec" CLASS="AccHDRLeftElem" ><BR></TD><TD CLASS="AccDataElem" >5</TD><TD CLASS="AccDataElem" >AAAA1</TD><TD CLASS="AccDataElem" >15344</TD><TD CLASS="AccDataElem" >2/2/2009</TD><TD CLASS="AccDataElem" >2/19/2009</TD><TD CLASS="AccDataElem" >Complete</TD><TD CLASS="AccDataElem" ><BR></TD></TR><TR ><TD ID="currRec" CLASS="AccHDRLeftElem" ><BR></TD><TD CLASS="AccDataElem" >6</TD><TD CLASS="AccDataElem" >BBBB1</TD><TD CLASS="AccDataElem" >15346</TD><TD CLASS="AccDataElem" >3/1/2009</TD><TD CLASS="AccDataElem" >3/3/2009</TD><TD CLASS="AccDataElem" >Incomplete</TD><TD CLASS="AccDataElem" ><BR></TD></TR><TR ><TD ID="IE" CLASS="AccIEOnlyMain" colSpan= 8 ><TABLE width="100%" align=left VALIGN="TOP" ><TR ><TD CLASS="AccIEOnlyInnerRight" > Record: </TD><TD CLASS="AccButton" ><img src='AccNavL.jpg' width='40' height='15'/></TD><TD CLASS="AccIEOnlyData" > 1 </TD><TD CLASS="AccButton" ><img src='AccNavR.jpg' width='40' height='15'/></TD><TD CLASS="AccIEOnlyInnerLeft" > of 6</TD></TR></TABLE></TD></TR><TR ><TD CLASS="AccIEOnlyMain" colSpan= 8 ><TABLE cellSpacing=0 cellPadding=0 width="100%" align=left VALIGN="TOP" ><TR ><TD ID="Data233837366" CLASS="AccInfoBarInnerRight" >TblTrainingRecord</TD><TD ID="Info233837366" CLASS="AccInfoBarData" > Record Count: 6</TD></TR></TABLE></TD></TR><TR ><TD CLASS="tpkrow" colSpan = 8 ><CENTER><font size = 1>Access HTML Add-in provided by theprimarykey.com</font></CENTER></TD></TR></TABLE></CENTER>
 
Upvote 0
Hi, Celes. Here's the "solution", which I've improved upon based on your latest business rules. However, I may not have understood those rules, so you might have two tweak the query. In any event the hard part is done. See below for my question. First, though, try out this SQL string:

Code:
SELECT tblManagers.SEID, tblManagers.LastName, tblManagers.TrainingLevel, tblCourseList.Level, tblCourseList.CourseNumber, tblCourseList.Course, [SEID] & "-" & [CourseNumber] AS MyID
FROM tblManagers, tblCourseList
WHERE (((tblCourseList.Level)<=[tblManagers].[TrainingLevel]) AND (([SEID] & "-" & [CourseNumber]) Not In (SELECT [AttendeeSEID] & "-" & [CourseNumber] AS MyID FROM TblTrainingRecord WHERE (((TblTrainingRecord.Status)="complete" Or (TblTrainingRecord.Status)="waived"));)))
ORDER BY tblManagers.SEID, tblManagers.TrainingLevel, tblCourseList.CourseNumber;
Notice that there is no join between the two tables. This is called a "Cartesian join" for reasons I'll research someday. The DLOOKUP criteria binds the two tables together in place of a join. This is the only way to get the less-than-or-equal-to "join" between the two tables.

In your background information from March 26 9pm, you mention in two places that the result should "only see people [not courses] at or below the training level". However, in your example you said that a manager hired at Level 4 "will not have to complete level 1 course". This is a contradiction. I went with the practical example's rules: In the SQL, a course is considered eligible for a particular manager if the COURSE'S level is equal to or less than the manager's level. For example, a Level 4 manager might have to take Level 0, 1, 2, 3, and 4 courses if they are not waived or already completed. If I am incorrect, you'll need to edit my query. It might simply be a matter of making <= to be >=.

Verify my SQL (and your changes) by (1) querying for all eligible courses and (2) querying for all completed/waived courses. All the courses listed for a manager in my SQL should be in Query 1, but not in Query 2.

Let me know if I can be of further help.
 
Upvote 0
For future visitors to this posting, here is how the SQL/query looks in "Datasheet View". It doesn't have a DLOOKUP as I said in my previous post, but a simple <= criterion.

Will_B_Query2.jpg
 
Last edited:
Upvote 0
Yes, yes, yes. Your analogy is correct; I apologize for my contradictions. This works exactly as I need. I would've never figured this out. You're awesome.

Thanks,
Celes
 
Upvote 0

Forum statistics

Threads
1,216,075
Messages
6,128,662
Members
449,462
Latest member
Chislobog

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top