Access query, find highest value in field

Posted on 2010-11-12
Medium Priority
Last Modified: 2012-05-10
Hi. I have a table, tblMe, which has a number field called Mod (along with a few other fields). I need to return all records which have the highest Mod number.

In other words, if there are 2 records with a Mod of 4, 6 records with a mod of 8, and 4 records with a mod of 12, I only want to see those last 4 records (the ones with a mod of 12 or whatever the highest number is at that time).

Thanks much.
Question by:pkromer
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
LVL 44

Assisted Solution

GRayL earned 400 total points
ID: 34124676
SELECT a.Fld1, a.Fld2, a.Mod FROM myTable a WHERE a.Mod IN (SELECT Top 1 b.Mod FROM myTable b
WHERE b.Fld1 & a.Fld2 = a.Fld1 & a.Fld2 ORDER BY b.Mod DESC) ORDER BY a.Fld1, a.Fld2, a.Mod DESC;
LVL 44

Expert Comment

ID: 34124692
Confirm you do not want to see any other associated fields with the top Mod value(s)?  If that is the case:

LVL 120

Accepted Solution

Rey Obrero (Capricorn1) earned 1600 total points
ID: 34124696

SELECT tblMe.ID, Max(tblMe.mod)
FROM tblMe
HAVING Max(tblMe.mod)=(select max([mod]) from tblMe)
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

LVL 44

Expert Comment

ID: 34124825
Thanks, but could you elaborate on how you decided to split the points, or for that matter, why you chose to close the question when I had a question outstanding?

Author Comment

ID: 34124938

I didn’t see that as a question, but rather an elaboration on your answer provided before it. I'm sorry, I certainly don't want to be awarding points inappropriately. It's just that capricorn1's answer got me there quickest.

I am about to open up another question related to this one because I just heard from the dept that needs this, they have additional criteria to add to the mix. So, if you want to try and help there I will certainly use your suggestions as much as possible. Thanks.
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34124976

if you want all the fields from the table, just use this query

select * from tblMe
where [mod]=(select max([mod]) from tblMe)

Author Comment

ID: 34124990
Thanks capricorn1, all good. As I said above, I am now opening another question based on this one. This one is complete, thanks again very much.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question