Results 1 to 3 of 3
  1. #1
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862

    Use alias to incorporate Query Object on Inner Join

    Not sure if the thread title is correct. I have two query objects that I would like to be one query object (use a single SQL string).



    The first query, qry_A_A_UnitsIn, establishes whether or not a given record in tblInvLumb has any related records in tblPieces. I include the field PurchOrdFK in the SELECT statemnt to provide a join to the second query.

    Code:
    SELECT tblInvLumb.PurchOrdFK, tblInvLumb.InvLumbPK, tblPieces.InWare
    FROM tblInvLumb INNER JOIN tblPieces ON tblInvLumb.InvLumbPK = tblPieces.InvLumbFK
    WHERE (((tblPieces.InWare)=False));
    The second query uses group by to provide a count of records in tblInvLumb for a given purchase order (record in tblPurchOrd). The second query joins the first query on PurchOrdPK/PurchOrdFK.

    Code:
    SELECT tblPurchOrd.PurchOrdPK, Count(qry_A_A_UnitsIn.InvLumbPK) AS CountUnits
    FROM tblPurchOrd INNER JOIN qry_A_A_UnitsIn ON tblPurchOrd.PurchOrdPK = qry_A_A_UnitsIn.PurchOrdFK
    GROUP BY tblPurchOrd.PurchOrdPK;
    I am curious if there is a way to use alias' to eliminate the need for qry_A_A_UnitsIn, as an object.

    Using Is Null to find unmatched records may be another approach but I want to try to learn a little more about creating alias'.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Should be possible. Switch second query to SQL view and copy/paste the first query.

    SELECT tblPurchOrd.PurchOrdPK, Count(qry_A_A_UnitsIn.InvLumbPK) AS CountUnits
    FROM tblPurchOrd INNER JOIN

    (SELECT tblInvLumb.PurchOrdFK, tblInvLumb.InvLumbPK, tblPieces.InWare
    FROM tblInvLumb INNER JOIN tblPieces ON tblInvLumb.InvLumbPK = tblPieces.InvLumbFK
    WHERE (((tblPieces.InWare)=False))) AS qry_A_A_UnitsIn

    ON tblPurchOrd.PurchOrdPK = qry_A_A_UnitsIn.PurchOrdFK
    GROUP BY tblPurchOrd.PurchOrdPK;
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    That is definately working. My previous attempts using 'AS' failed. I will have to go back and see what I was doing wrong. Thanks for spacing out the SQL in your post.

    Now I have something I can use at the form level to dynamicaly adjust Recordsets/Rowsources without stumbling over so many query objects.

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

Similar Threads

  1. Replies: 6
    Last Post: 12-11-2013, 09:54 PM
  2. Replies: 2
    Last Post: 06-12-2013, 10:23 AM
  3. Replies: 46
    Last Post: 05-16-2013, 09:53 PM
  4. Replies: 7
    Last Post: 02-20-2012, 07:19 PM
  5. Replies: 1
    Last Post: 02-08-2012, 01:33 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