A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Min value & corresponding date



 
 
Thread Tools Display Modes
  #1  
Old April 28th, 2010, 03:10 PM posted to microsoft.public.access.queries
woods1119
external usenet poster
 
Posts: 12
Default Min value & corresponding date

I need to get the min value of FVC% and the corresponding date that goes
along with this value. I've had no luck just trying to use min from the
totals option. This is what I have.

From table (tPFT) I need to following fields ingPtID, STUDY_DATE, FVC%


ingPtID and STUDY_DATE are both primary keys if that makes a difference.
  #2  
Old April 28th, 2010, 03:25 PM posted to microsoft.public.access.queries
Daryl S[_2_]
external usenet poster
 
Posts: 881
Default Min value & corresponding date

woods1119 -

This will pull all records where the FVC% is the min(FVC%) in the table:

SELECT ingPtID, STUDY_DATE, FVC%
FROM tPFT
WHERE FVC% = (SELECT min(FVC%) FROM tPFT);

--
Daryl S


"woods1119" wrote:

I need to get the min value of FVC% and the corresponding date that goes
along with this value. I've had no luck just trying to use min from the
totals option. This is what I have.

From table (tPFT) I need to following fields ingPtID, STUDY_DATE, FVC%


ingPtID and STUDY_DATE are both primary keys if that makes a difference.

  #3  
Old April 28th, 2010, 03:33 PM posted to microsoft.public.access.queries
Tom van Stiphout[_2_]
external usenet poster
 
Posts: 1,653
Default Min value & corresponding date

On Wed, 28 Apr 2010 07:10:10 -0700, woods1119
wrote:

The general query is like this:
select * from myTable
where myField = (select Min(myField) from myTable)

-Tom.
Microsoft Access MVP



I need to get the min value of FVC% and the corresponding date that goes
along with this value. I've had no luck just trying to use min from the
totals option. This is what I have.

From table (tPFT) I need to following fields ingPtID, STUDY_DATE, FVC%


ingPtID and STUDY_DATE are both primary keys if that makes a difference.

  #4  
Old April 28th, 2010, 03:40 PM posted to microsoft.public.access.queries
woods1119
external usenet poster
 
Posts: 12
Default Min value & corresponding date

Thanks!

It is recognizing the '%' as a syntax error though. I imagine that whoever
developed the database poorly chose to use the % in naming...?

"Daryl S" wrote:

woods1119 -

This will pull all records where the FVC% is the min(FVC%) in the table:

SELECT ingPtID, STUDY_DATE, FVC%
FROM tPFT
WHERE FVC% = (SELECT min(FVC%) FROM tPFT);

--
Daryl S


"woods1119" wrote:

I need to get the min value of FVC% and the corresponding date that goes
along with this value. I've had no luck just trying to use min from the
totals option. This is what I have.

From table (tPFT) I need to following fields ingPtID, STUDY_DATE, FVC%


ingPtID and STUDY_DATE are both primary keys if that makes a difference.

  #5  
Old April 28th, 2010, 05:27 PM posted to microsoft.public.access.queries
Marshall Barton
external usenet poster
 
Posts: 5,361
Default Min value & corresponding date

woods1119 wrote:

I need to get the min value of FVC% and the corresponding date that goes
along with this value. I've had no luck just trying to use min from the
totals option. This is what I have.

From table (tPFT) I need to following fields ingPtID, STUDY_DATE, FVC%

ingPtID and STUDY_DATE are both primary keys if that makes a difference.



Does this do what you want"

SELECT TOP 1 ingPtID, STUDY_DATE, [FVC%]
FROM table
ORDER BY [FVC%]

--
Marsh
MVP [MS Access]
  #6  
Old April 28th, 2010, 06:23 PM posted to microsoft.public.access.queries
Daryl S[_2_]
external usenet poster
 
Posts: 881
Default Min value & corresponding date

Put all table names, field names, control names, etc. that have a special
character (including spaces) in square brackets. [FVC%] instead of FVC%.

--
Daryl S


"woods1119" wrote:

Thanks!

It is recognizing the '%' as a syntax error though. I imagine that whoever
developed the database poorly chose to use the % in naming...?

"Daryl S" wrote:

woods1119 -

This will pull all records where the FVC% is the min(FVC%) in the table:

SELECT ingPtID, STUDY_DATE, FVC%
FROM tPFT
WHERE FVC% = (SELECT min(FVC%) FROM tPFT);

--
Daryl S


"woods1119" wrote:

I need to get the min value of FVC% and the corresponding date that goes
along with this value. I've had no luck just trying to use min from the
totals option. This is what I have.

From table (tPFT) I need to following fields ingPtID, STUDY_DATE, FVC%


ingPtID and STUDY_DATE are both primary keys if that makes a difference.

  #7  
Old May 4th, 2010, 05:09 PM posted to microsoft.public.access.queries
woods1119
external usenet poster
 
Posts: 12
Default Min value & corresponding date

Unfortunately none of these are working.

There are about 2500 unique ingPtID in the database. Each of these
ingPtID's will have a STUDY_DATE and FVC%. I would like to get the minimum
FVC% & corresponding date for each ingPTID. I'm hoping that further info
might help.

Thanks!

"Marshall Barton" wrote:

woods1119 wrote:

I need to get the min value of FVC% and the corresponding date that goes
along with this value. I've had no luck just trying to use min from the
totals option. This is what I have.

From table (tPFT) I need to following fields ingPtID, STUDY_DATE, FVC%

ingPtID and STUDY_DATE are both primary keys if that makes a difference.



Does this do what you want"

SELECT TOP 1 ingPtID, STUDY_DATE, [FVC%]
FROM table
ORDER BY [FVC%]

--
Marsh
MVP [MS Access]
.

  #8  
Old May 4th, 2010, 06:55 PM posted to microsoft.public.access.queries
Marshall Barton
external usenet poster
 
Posts: 5,361
Default Min value & corresponding date

woods1119 wrote:

Unfortunately none of these are working.

There are about 2500 unique ingPtID in the database. Each of these
ingPtID's will have a STUDY_DATE and FVC%. I would like to get the minimum
FVC% & corresponding date for each ingPTID. I'm hoping that further info
might help.



In that case try something more like:

SELECT ingPtID, STUDY_DATE, [FVC%]
FROM table
INNER JOIN (SELECT X.ingPtID, Min([FVC%]) As MinPct
FROM table As X
GROUP BY X.ingPtID) As M
ON M.ingPtID = table.ingPtID
And M.MinPct = table.MinPct

--
Marsh
MVP [MS Access]
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:14 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.