Criteria of One query based on a field in another query

D

DawnP277

I am trying to create a query that is going to look at the last record that
was entered (this will hold the key piece of information).

I created a query based on Last for Date and Time, and provides me the
serial number that I want to use as criteria for another query.

I am wondering how to take the serial number that is returned from one query
(the query only returns one line) and use this as an equal another query.

Any advice

Thanks
Dawn
 
J

Jerry Whittle

First I would highly recommend using Max instead of Last. Last depends of the
sort order of the returned records, whereas Max will look for the "last" time
without worrying about the sort order. This is true if the field is an actual
date/time datatype.

You could do what you want with a subquery. Please provide the SQL statement
for getting the "last" date plus the SQL statement for something close to the
other query. I'll see what I can cobble together.

Open the query in design view. Next go to View, SQL View and copy and past
it here.
 
D

DawnP277

Thank Jerry, I think I was able to create my subquery.

I took your advice and changed the last to Max.

Here is the SQL for my query. It appears to do what I need.

SELECT Query1.Date, Query1.Time, Query1.[Sample ID], Query1.[Displacement
(in)], Query1.[Load (lbf)], Query1.[Hydraulic Pressure (psi)], Query1.[Test
Part Area], Query1.[Stress (psi)], Query1.[Ram Position (in)], [Last Record
Added].[LastOfSample ID]
FROM [Last Record Added] INNER JOIN Query1 ON [Last Record
Added].[LastOfSample ID] = Query1.[Sample ID];
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top