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'.