Solved

Access query, find highest value in field

Posted on 2010-11-12
7
507 Views
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.
0
Comment
Question by:pkromer
  • 3
  • 2
  • 2
7 Comments
 
LVL 44

Assisted Solution

by:GRayL
GRayL earned 100 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;
0
 
LVL 44

Expert Comment

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

SELECT Top 1 Mod FROM myTable ORDER BY Mod DESC;
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 400 total points
ID: 34124696

SELECT tblMe.ID, Max(tblMe.mod)
FROM tblMe
GROUP BY tblMe.ID
HAVING Max(tblMe.mod)=(select max([mod]) from tblMe)
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 44

Expert Comment

by:GRayL
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?
0
 

Author Comment

by:pkromer
ID: 34124938
GRayL,

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.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34124976
pkromer,

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

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

Author Comment

by:pkromer
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.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

803 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