sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
james.eacret@gmail.com's Avatar

Max Function


Question posted by: james.eacret@gmail.com (Guest) on July 12th, 2006 10:05 PM
Hello all,

I am stuck on a query, and was hoping for some help. I'm using Access
2003 with a WinXP machine.

I need to find the Max value of a chemical, and also include SiteID,
SampleID,Units, and Comments.

Example:

SampleID SiteID Chemical Results Units Comments
Sample1 A Chem1 1 L XXXX
Sample2 B Chem2 30 L XXXX
Sample3 C Chem1 5 L
Sample4 D Chem1 3 L
XXXXX
Sampe5 F Chem2 22 L XXXXX

The Query would show:
SampleID SiteID Chemical Results Units Comments
Sample2 B Chem2 30 L XXXX
Sample3 C Chem1 5 L

The Max Function does this, however, if I add any other field, it gives
me the Max Result for each Site, Sample and Chemical....

Any Thoughts?

Thanks in advance

3 Answers Posted
CDMAPoster@FortuneJames.com's Avatar
CDMAPoster@FortuneJames.com July 12th, 2006 10:25 PM
Guest - n/a Posts
#2: Re: Max Function

Join Bytes! wrote:
Quote:
Originally Posted by
Hello all,
>
I am stuck on a query, and was hoping for some help. I'm using Access
2003 with a WinXP machine.
>
I need to find the Max value of a chemical, and also include SiteID,
SampleID,Units, and Comments.
>
Example:
>
SampleID SiteID Chemical Results Units Comments
Sample1 A Chem1 1 L XXXX
Sample2 B Chem2 30 L XXXX
Sample3 C Chem1 5 L
Sample4 D Chem1 3 L
XXXXX
Sampe5 F Chem2 22 L XXXXX
>
The Query would show:
SampleID SiteID Chemical Results Units Comments
Sample2 B Chem2 30 L XXXX
Sample3 C Chem1 5 L
>
The Max Function does this, however, if I add any other field, it gives
me the Max Result for each Site, Sample and Chemical....
>
Any Thoughts?
>
Thanks in advance


Try:

SELECT SampleID, SiteID, Chemical, Results, Units, Comments FROM
tblSamples WHERE Results = (SELECT MAX(A.Results) FROM tblSamples AS A
WHERE A.Chemical = tblSamples.Chemical);

Note that ties for Max(Results) for a given Chemical will all show.

James A. Fortune
Join Bytes!

james.eacret@gmail.com's Avatar
james.eacret@gmail.com July 13th, 2006 04:05 PM
Guest - n/a Posts
#3: Re: Max Function

Worked like a charm, thank you very much!

James

CDMAPoster@FortuneJames.com's Avatar
CDMAPoster@FortuneJames.com July 13th, 2006 04:35 PM
Guest - n/a Posts
#4: Re: Max Function

Join Bytes! wrote:
Quote:
Originally Posted by
Worked like a charm, thank you very much!
>
James


I'm glad it gave you the results you wanted.

Based on information from one of Salad's recent posts somewhere, also
try using the DMax function to see if it affects the query's speed:

SELECT SampleID, SiteID, Chemical, Results, Units, Comments FROM
tblSamples WHERE Results = DMax("Results", "tblSamples", "Chemical = "
& Chr(34) & tblSamples.Chemical & Chr(34));

James A. Fortune
Join Bytes!

In reality the texts of the Rosetta Stone were of limited use because
the hieroglyphs were so damaged, as Champollion had pointed out in his
'Lettre à M. Dacier': 'The hieroglyphic text of the Rosetta
inscription, which should have lent itself so happily to this research,
because of its breaks only presented the single name of Ptolemy.'
Having become the focus of attention for would-be decipherers, the
Rosetta Stone still remains a powerful popular symbol, even though its
inscriptions failed to fulfil the hopes and expectations they aroused.
Other inscriptions and papyri were far more important in providing
clues to decipherment. -- The Keys of Egypt, Lesley and Roy Adkins,
ISBN 0-06-095349-7

 
Not the answer you were looking for? Post your question . . .
197,043 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 197,043 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors