title: Connecting multiple queries and passing criteria from one query to another
body: <p>I am trying to put together a query that will basically run another query on each return.</p>
  <p>My current query puts together important info for each client, such as how long an average groom takes and the description of the type of haircut they get:</p>
  <pre><code>SELECT Query11.petId AS PetID,
         Query11.petName AS PetName,
         dbo_Customer.cstLName AS LastName,
         Query11.lstValue AS Breed,
         qryFindsPetAvgApptTime.TotalAppts,
         dbo_vwPetGroom.pgrName AS GroomStyle,
         dbo_ListValues.lstValue AS Haircut,
         ROUND([AvgPTime]) AS AvgPrep,
         ROUND([AvgBTime]) AS AvgBath,
         ROUND([AvgDTime]) AS AvgDry,
         ROUND([AvgGTime]) AS AvgGroom,
         [AvgPrep] + [AvgBath] + [AvgDry] + [AvgGroom] AS AvgMinutes,
         qryFindsPetAvgApptTime.AvgHours
  FROM((Query11
        LEFT JOIN qryFindsPetAvgApptTime ON Query11.petId = qryFindsPetAvgApptTime.PetID)
       LEFT JOIN dbo_Customer ON Query11.petCustId = dbo_Customer.cstId)
      LEFT JOIN (dbo_vwPetGroom
                 LEFT JOIN dbo_ListValues ON dbo_vwPetGroom.pgrLengthHairBodyLid = dbo_ListValues.lstId)
                                ON Query11.petId = dbo_vwPetGroom.pgrPetId;
  </code></pre>
  <p>I want to add in the average length between grooming appts to the above query info. Right now that is done in 2 seperate queries.
  The first one pulls days between appts:</p>
  <pre><code>SELECT tblTimeLog.PetID,
         tblTimeLog.PetName,
         [ApptDate] - (SELECT MAX(T.ApptDate)
                       FROM tblTimeLog T
                       WHERE T.PetID = tblTimeLog.PetID
                         AND T.ApptDate &lt; tblTimeLog.ApptDate) AS Diff,
         tblTimeLog.ApptDate
  FROM tblTimeLog
  WHERE (((tblTimeLog.PetID) = [Enter PetID]))
  ORDER BY tblTimeLog.ApptDate;
  </code></pre>
  <p>And then averaged out with this:</p>
  <pre><code>SELECT qryTimeLogDiffs.PetID,
         qryTimeLogDiffs.PetName,
         AVG(qryTimeLogDiffs.Diff) AS AvgOfDiff
  FROM qryTimeLogDiffs
  GROUP BY qryTimeLogDiffs.PetID,
           qryTimeLogDiffs.PetName;
  </code></pre>
  <p>Is there a way to pass the PetID criteria from each return into the second query so it adds the average span between appts to the info in the first query??</p>