Results 1 to 3 of 3
  1. #1
    kman42 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    40

    Nested join problem

    I have a single table that I am trying to extract some information from. I had previously used two queries, with one referencing the other as follows:



    Project_IDs:
    Code:
    SELECT Applications.[Project ID]
    FROM Applications
    WHERE (((Applications.[Grant Num Appl])="2") AND ((Applications.[Grant Num Supp Yr])>"2") AND ((Applications.[Grant Num Act])="R44") AND ((Applications.[Stat Grp])="A")) OR (((Applications.[Grant Num Appl])="2") AND ((Applications.[Grant Num Supp Yr])>"2") AND ((Applications.[Grant Num Act])="R42") AND ((Applications.[Stat Grp])="A"))
    GROUP BY Applications.[Project ID];
    Code:
    SELECT [Grant Num IC] & [Grant Num Serial] AS [Project ID], Last(Applications.Institution) AS Institution, Last(Applications.[PI Name (Contact)]) AS [PI Name (Contact)], Last(Applications.Title) AS Title, Last(Applications.[Proj Start]) AS [Proj Start], Last(Applications.[Proj End]) AS [Proj End], Last(Applications.[PI Phone]) AS [PI Phone], Last(Applications.[PI Email]) AS [PI Email], Last(Applications.[PI Fax]) AS [PI Fax], Last(Applications.[PI Addr]) AS [PI Addr], IIf(Sum(IIf([Applications].[Active]="Y",1,0)>0),"Y","N") AS Active, IIf(Sum(IIf([Applications].[Stat Grp]="A",1,0)>0),"Y","N") AS [Stat Grp], Last(Applications.[RFA Title]) AS [RFA Title], Sum(Applications.[Awd Tot $ by IC]) AS [SumOfAwd Tot $ by IC], Last(Applications.Remarks) AS Remarks, Last(Applications.FPR) AS FPR
    FROM Project_IDs INNER JOIN Applications ON Project_IDs.[Project ID]=Applications.[Project ID]
    GROUP BY [Grant Num IC] & [Grant Num Serial]
    HAVING (((IIf(Sum(IIf([Applications].[Stat Grp]="A",1,0)>0),"Y","N"))="Y"));
    I would really like this to be in a single query, so I am trying to nest it as follows:

    Code:
    SELECT [Grant Num IC] & [Grant Num Serial] AS [Project ID], Last(Applications.Institution) AS Institution, Last(Applications.[PI Name (Contact)]) AS [PI Name (Contact)], Last(Applications.Title) AS Title, Last(Applications.[Proj Start]) AS [Proj Start], Last(Applications.[Proj End]) AS [Proj End], Last(Applications.[PI Phone]) AS [PI Phone], Last(Applications.[PI Email]) AS [PI Email], Last(Applications.[PI Fax]) AS [PI Fax], Last(Applications.[PI Addr]) AS [PI Addr], IIf(Sum(IIf([Applications].[Active]="Y",1,0)>0),"Y","N") AS Active, IIf(Sum(IIf([Applications].[Stat Grp]="A",1,0)>0),"Y","N") AS [Stat Grp], Last(Applications.[RFA Title]) AS [RFA Title], Sum(Applications.[Awd Tot $ by IC]) AS [SumOfAwd Tot $ by IC], Last(Applications.Remarks) AS Remarks, Last(Applications.FPR) AS FPR
    FROM ((SELECT Applications.[Project ID] as p
    FROM Applications
    WHERE (((Applications.[Grant Num Appl])="2") AND ((Applications.[Grant Num Supp Yr])>"2") AND ((Applications.[Grant Num Act])="R44") AND ((Applications.[Stat Grp])="A")) OR (((Applications.[Grant Num Appl])="2") AND ((Applications.[Grant Num Supp Yr])>"2") AND ((Applications.[Grant Num Act])="R42") AND ((Applications.[Stat Grp])="A"))
    GROUP BY Applications.[Project ID]) INNER JOIN Applications ON p=Applications.[Project ID])
    GROUP BY [Grant Num IC] & [Grant Num Serial]
    HAVING (((IIf(Sum(IIf([Applications].[Stat Grp]="A",1,0)>0),"Y","N"))="Y"));
    I keep getting "JOIN expression not supported"

    I realize this is a complicated set of queries and probably not the best way to do this, but I am very new to Access and SQL so I am just trying to get it working. Any help would be greatly appreciated.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    I agree it's a complex query. And none of us has any knowledge of your situation or what exactly you are trying to accomplish.
    Have you tried running simpler queries and get intermediate results?
    Do you have any test records such that you know that parts of this query are working correctly?

    I have reformatted your query (trying to simplify it) but I may have missed something.
    I'm surprised with the number of immediate iif's.

    SELECT [Grant Num IC] & [Grant Num Serial] AS [Project ID]
    , Last(Applications.Institution) AS Institution
    , Last(Applications.[PI Name (Contact)]) AS [PI Name (Contact)]
    , Last(Applications.Title) AS Title
    , Last(Applications.[Proj Start]) AS [Proj Start]
    , Last(Applications.[Proj End]) AS [Proj End]
    , Last(Applications.[PI Phone]) AS [PI Phone]
    , Last(Applications.[PI Email]) AS [PI Email]
    , Last(Applications.[PI Fax]) AS [PI Fax]
    , Last(Applications.[PI Addr]) AS [PI Addr]
    , IIf(Sum(IIf([Applications].[Active]="Y",1,0)>0),"Y","N") AS Active
    , IIf(Sum(IIf([Applications].[Stat Grp]="A",1,0)>0),"Y","N") AS [Stat Grp]
    , Last(Applications.[RFA Title]) AS [RFA Title]
    , Sum(Applications.[Awd Tot $ by IC]) AS [SumOfAwd Tot $ by IC]
    , Last(Applications.Remarks) AS Remarks
    , Last(Applications.FPR) AS FPR
    FROM ((SELECT Applications.[Project ID] as p
    FROM Applications
    WHERE Applications.[Grant Num Appl]="2" AND
    Applications.[Grant Num Supp Yr])>"2" AND
    Applications.[Stat Grp])="A" AND
    (Applications.[Grant Num Act]="R44" OR Applications.[Grant Num Act])="R42")
    GROUP BY Applications.[Project ID])
    INNER JOIN Applications ON p=Applications.[Project ID])
    GROUP BY [Grant Num IC] & [Grant Num Serial]
    HAVING (((IIf(Sum(IIf([Applications].[Stat Grp]="A",1,0)>0),"Y","N"))="Y"));
    Good luck.

  3. #3
    kman42 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    40
    Thanks, I just solved the problem. I had to assign the internal query using the AS function. So:

    (SELECT ...) AS InnerQuery INNER JOIN OtherQuery ON InnerQuery.Field=OtherQuery.Field

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Left join problem
    By e.badin in forum Queries
    Replies: 5
    Last Post: 01-17-2011, 08:03 AM
  2. Another Nested IIF Query problem
    By Brian Collins in forum Queries
    Replies: 8
    Last Post: 10-22-2010, 10:12 AM
  3. Problem with Join
    By sujitshukla in forum Queries
    Replies: 1
    Last Post: 08-26-2010, 07:25 AM
  4. Many to many self-join problem
    By dbdbdo in forum Database Design
    Replies: 1
    Last Post: 07-18-2010, 09:31 AM
  5. Returning correct rows in a join/nested query
    By goneaccessing in forum Queries
    Replies: 5
    Last Post: 03-03-2010, 12:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums