Query with nested queries

psycoperl

Active Member
Joined
Oct 23, 2007
Messages
339
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
Need some guidance/advice:
When I am running this query, I am getting "The multi-valued field 'Seats.tsTestTypes' is not valid in the specified JOIN Clause"

In my tblTestSessions.tsTestTypes I have the list of all the TestCodes that can be issued for that session.

I am trying to get a list of the sessions that have seats available and are in the future.

HELP!

Code:
SELECT 
 Seats.tsTestSessionID, 
 Seats.tsTestSessionDateTime, 
 Seats.SeatsAvailable
FROM 
 (SELECT 
    tblTestSessions.tsTestSessionID, 
    tblTestSessions.tsTestTypes, 
    tblTestSessions.tsTestSessionDateTime, 
    tblTestSessions.tsMaxRegistration, 
    tblTestSessions.tsMaxRegistrationOverride, 
    tblTestSessions.tsRoom, 
    IIf(IsNull([APT].[NumOfAppt]),0,[APT].[NumOfAppt]) AS NumOfAppt, 
    tblTestSessions.tsMaxRegistration-IIf(IsNull([APT].[NumOfAppt]),0,[APT].[NumOfAppt]) AS SeatsAvailable
  FROM tblTestSessions LEFT JOIN 
    (SELECT 
       tblStudentAppointments.aptSession, 
       Count(tblStudentAppointments.aptRecordID) AS NumOfAppt 
     FROM tblStudentAppointments 
     GROUP BY tblStudentAppointments.aptSession) AS APT 
  ON tblTestSessions.tsTestSessionID = APT.aptSession) AS SEATS INNER JOIN 
      (SELECT 
         STN.* 
         FROM tblStudentTestNeeds AS STN INNER JOIN 
            (SELECT 
                tblStudentTestNeeds.tnStudentID, 
                Max(tblStudentTestNeeds.tnDateEntered) AS MaxOftnDateEntered 
                FROM tblStudentTestNeeds 
                GROUP BY tblStudentTestNeeds.tnStudentID) AS MRTC 
  ON (STN.tnDateEntered = MRTC.MaxOftnDateEntered) 
     AND (STN.tnStudentID = MRTC.tnStudentID)) As NEEDS 
ON NEEDS.tnTestCode = Seats.tsTestTypes
WHERE
 Seats.tsTestSessionDateTime > now()
 AND
 Seats.SeatsAvailable > (-1*Seats.tsMaxRegistrationOverride)
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi Joe4:
I see. Can you provide some guidance on how to get out of "nasty" situation?

I actually only have this one multivalue field in my database. it is storing tiTestID values from tblTestInfo in my tblTestSessions table which shows which test codes are offered for each session.

Since I am in still in full development, now would be a good time to remove "crap" that could hinder before I start loading thousands of records into my database.
 
Upvote 0
Like I said, I have never used them, so I am not sure what the best way of correcting it is. One approach they mentioned in that thread I mentioned is:
The "classic" approach (which is actually what Access does under the covers
with multi-value fields) is to introduce a third table to resolve the
many-to-many relationship.
 
Upvote 0

Forum statistics

Threads
1,224,537
Messages
6,179,408
Members
452,912
Latest member
alicemil

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