Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Maximum as a query field criterion

Status
Not open for further replies.

carmenlisa

Technical User
Feb 9, 2012
20
0
0
US
I need to query a table that contains results of surveys for various pieces of property. One of the fields will be number, beginning with 1, that indicated which survey this set of data represents. I will definitely at times want the data from the first survey and that is an easy query.

But what about when I was the last (highest number) query on a property? That is, for the survey number field, rather than putting in a number (because each property has a different nunber of surveys and I don't readily know how many surveys a given piece of property has had) I want to use the equivalent of MAX in Excel. That is, my criteria for that field is to find the record where that field has the largest value.

If I am not clear, I may have 7 entries for various surveys done over time for Property A. Then again, I may have only two surveys or as many as dozens. I know I could easily run a query to show me how many there are so I would no the highest number used for Property A, but that is a pain to do.

So the question is, can I just put Max or Maximum into the query criterion box for the SurveyNumber field and Property A in that field and get the survey results I am looking for, that is the results for the last survey entered?
 
What is your actual SQL code ?
Hint: use =(Select Max(SurveyNumber) FROM ... WHERE ...)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
First, I should admit that I am not a SQL guy. I sort of understand it, but when I cannot use the Access Query interface, I need to go to books for how to adjust the SQL.

I believe I have discovered an easier way to do this. If I first to a sub query, use the property and survey fields (specifying the property and returning only the survey number in the result), I believe that all I need to do is set the survey number field in descending order and set the properties of the query to return the top one result. And then use this query as part of the basis for my later query to get the results of the needed survey for the specified property.

Anyone see any difficulties in that approach? If not, it is a fairly simple system to use.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top