Chat with a LIVE Microsoft Access Expert!
 
       
 

         

   

Go Back   Access World Forums > Microsoft Access Discussion > Queries

 
 
Chat with a LIVE Microsoft Access Expert!
Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-01-2006, 07:02 AM
Kelemit Kelemit is offline
Registered User
 
Join Date: Mar 2006
Posts: 57
Kelemit is on a distinguished road
Query in a Query.

I hope I can get some help on this. This is by far my weakest area in creating databases.

Queries:

I need a query that allows me to find the highest number in a field for each set in that table.

IE: I have a master table of classes, and a linked table (one to many) of revisions / versions of that specific class. I want to return ONLY THE MOST RECENT version of each class. I know how to show the top 1 return (showing descending order on version field), but that only returns the HIGHEST version for any ONE class. Any class that has only a single revision, or revisions lesser than the greatest will not be shown.

Anyway to be able to do this?

My idea at the moment is somthing along the lines of a query within a query, but i'm stumped at the moment on how to accomplish this.

Something like:

SELECT ClassTable.Classes, (Select TOP 1 VersionsTable.ClassVersion FROM VersionTable Order By VersionTable.ClassVersion DESC AS VersionList FROM ClassTable;

This query returns all the classes, but only the highest version of one specific class for ALL classes. (IE: Class1 has 6 revisions, 2 and 3 only have 2 Revisions, but Class 1, 2, and 3 all show that Revision 6 is the latest revisions for all 3 classes, where they should be returning 6 revisions for class1, and 2 revisions for classes 2 and 3.)

Any help would be great

Kelemit
Reply With Quote
Sponsored Links
  #2  
Old 09-01-2006, 09:39 AM
ByteMyzer ByteMyzer is offline
AWF VIP
 
Join Date: May 2004
Location: United States
Posts: 1,214
ByteMyzer has a spectacular aura aboutByteMyzer has a spectacular aura aboutByteMyzer has a spectacular aura about
What are your table structures? (table names, field names in each table)
Reply With Quote
  #3  
Old 09-01-2006, 11:14 AM
Kelemit Kelemit is offline
Registered User
 
Join Date: Mar 2006
Posts: 57
Kelemit is on a distinguished road
Table structures

Table: Classes
ClassID (PK)
ClassNumber (text)
Defunct (Yes/No)

Table: ClassVersions
ClassID (Many to One to table Classes)
VersionID (PK)
Name
Hours
Classified
CourseType
HoursApplied
Knowledge
ValidTimeLength
Version (This is the field that IDs the Latest version. Higher the number
the more recent the version.)

The are linked 1 to Many through ClassID.


Other Tables:

Table: ClassesTaken (The classes that students have taken)
ClassesTakenID (PK)
VersionID
EmployeeID

Table: Employees
EmployeeID
Name
Address
Etc.

These three are linked through their appropriate IDs. Both ClassVersion and Employee are linked 1 to many to ClassesTaken.


Want to return ONLY the most recent version for EACH class listed in a drop down box. So was hoping for a query showing all classes, but only the latest version of that class, so that the VersionID number can be placed in the table that will keep track of what classes students have taken. VersionID is used because Class can be retrieved with it, as well knowing which version of that class the student took.

Kelemit.
Reply With Quote
  #4  
Old 09-01-2006, 12:27 PM
ByteMyzer ByteMyzer is offline
AWF VIP
 
Join Date: May 2004
Location: United States
Posts: 1,214
ByteMyzer has a spectacular aura aboutByteMyzer has a spectacular aura aboutByteMyzer has a spectacular aura about
If you want to return the ClassID and VersionID fields in your query, the following query/in-line query solution should give you what you need:
Code:
SELECT Classes.ClassID, ClassVersions.VersionID
FROM (Classes INNER JOIN ClassVersions ON Classes.ClassID=ClassVersions.ClassID)
INNER JOIN 
 (SELECT ClassID, Max(Version) AS xVersion
  FROM ClassVersions
  GROUP BY ClassID
 ) AS ClassVersions_1
ON ClassVersions.ClassID=ClassVersions_1.ClassID
AND ClassVersions.Version=ClassVersions_1.xVersion;
Reply With Quote
Sponsored Links
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pulling data from several identical tables and returning the results to one big query morlan Queries 5 01-23-2007 04:17 AM
Adding a Auto increment Text/Number elliotth123 Tables 12 09-13-2006 04:18 AM
Query by Form (w/Date & Memo fields) esskaykay Modules & VBA 5 12-30-2003 01:38 PM
Query for a report morlan Queries 1 11-16-2003 09:06 PM
Help returning blank (no entry) records with a parameter query rgsmpx Queries 2 10-09-2001 09:04 AM


All times are GMT -8. The time now is 10:00 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
(c) copyright 2009 Access World