dbTalk Databases Forums  

Max Date in a query whilst showing all fields

comp.databases.ms-access comp.databases.ms-access


Discuss Max Date in a query whilst showing all fields in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
franc sutherland
 
Posts: n/a

Default Max Date in a query whilst showing all fields - 07-02-2010 , 06:10 AM






Hi,
I'm using Access 2003, Windows XP.

I have a table of company turnover data. I want to query out the most
recent entry, by date, for each company (The most recent entry by
date, won't always be the most recent keyed in).
Using the MAX total in a Select query means that I have to remove all
fields except company_id and date, then Group on the company_id to
remove duplicate entries for a company. Is it possible to have all
five fields displayed whilst only showing the most recent entry, by
date, for each company?

The table is tbl_turnover

The fields are
turnover_id (autonumber)
turnover_company_id (integer)
turnover_year (date)
turover_amount (integer)

I've tried to use a sub-query but have been going round and round in
circles.

Any help would be greatly appreciated. I should know this, but I
can't get it to work!!

Thanks,

Franc.

Reply With Quote
  #2  
Old   
Allen Browne
 
Posts: n/a

Default Re: Max Date in a query whilst showing all fields - 07-02-2010 , 07:39 AM






The most efficient way to do this might be to make a simple Totals query
that just returns the company and max date:
SELECT turnover_company_id,
Max(turnover_year) AS TheDate
FROM tbl_turnover
GROUP BY turnover_company_id;

Save that query, and use it as an input 'table' for another query, along
with your original table. Join them on the company and date. This inner join
restricts it to the desired record, and you can then get all the fields you
want from the main table.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"franc sutherland" <franc.sutherland (AT) googlemail (DOT) com> wrote

Quote:
Hi,
I'm using Access 2003, Windows XP.

I have a table of company turnover data. I want to query out the most
recent entry, by date, for each company (The most recent entry by
date, won't always be the most recent keyed in).
Using the MAX total in a Select query means that I have to remove all
fields except company_id and date, then Group on the company_id to
remove duplicate entries for a company. Is it possible to have all
five fields displayed whilst only showing the most recent entry, by
date, for each company?

The table is tbl_turnover

The fields are
turnover_id (autonumber)
turnover_company_id (integer)
turnover_year (date)
turover_amount (integer)

I've tried to use a sub-query but have been going round and round in
circles.

Any help would be greatly appreciated. I should know this, but I
can't get it to work!!

Thanks,

Franc.

Reply With Quote
  #3  
Old   
Salad
 
Posts: n/a

Default Re: Max Date in a query whilst showing all fields - 07-02-2010 , 10:12 AM



Allen Browne wrote:
Quote:
The most efficient way to do this might be to make a simple Totals query
that just returns the company and max date:
SELECT turnover_company_id,
Max(turnover_year) AS TheDate
FROM tbl_turnover
GROUP BY turnover_company_id;

Save that query, and use it as an input 'table' for another query, along
with your original table. Join them on the company and date. This inner
join restricts it to the desired record, and you can then get all the
fields you want from the main table.

That certainly would be the quickest and more effecient. Another option
is using Dmax()

Reply With Quote
  #4  
Old   
franc sutherland
 
Posts: n/a

Default Re: Max Date in a query whilst showing all fields - 07-02-2010 , 10:16 AM



On Jul 2, 1:39*pm, "Allen Browne" <AllenBro... (AT) SeeSig (DOT) invalid> wrote:
Quote:
The most efficient way to do this might be to make a simple Totals query
that just returns the company and max date:
SELECT turnover_company_id,
Max(turnover_year) AS TheDate
FROM tbl_turnover
GROUP BY * turnover_company_id;

Save that query, and use it as an input 'table' for another query, along
with your original table. Join them on the company and date. This inner join
restricts it to the desired record, and you can then get all the fields you
want from the main table.

--
Allen Browne - Microsoft MVP. *Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"franc sutherland" <franc.sutherl... (AT) googlemail (DOT) com> wrote in message

news:e12e6155-851f-485e-a624-73c6ea5603dc (AT) i1g2000vbk (DOT) googlegroups.com...

Hi,
I'm using Access 2003, Windows XP.

I have a table of company turnover data. *I want to query out the most
recent entry, by date, for each company (The most recent entry by
date, won't always be the most recent keyed in).
Using the MAX total in a Select query means that I have to remove all
fields except company_id and date, then Group on the company_id to
remove duplicate entries for a company. *Is it possible to have all
five fields displayed whilst only showing the most recent entry, by
date, for each company?

The table is tbl_turnover

The fields are
turnover_id (autonumber)
turnover_company_id (integer)
turnover_year (date)
turover_amount (integer)

I've tried to use a sub-query but have been going round and round in
circles.

Any help would be greatly appreciated. *I should know this, but I
can't get it to work!!

Thanks,

Franc.
Hi Allen,

Thanks for your help, works a treat.

All the best,

Franc.

Reply With Quote
Reply




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 On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.