473,503 Members | 11,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query most recent records for unique field values

17 New Member
Hello-

I'm having a little trouble. I want to create a query that will return the most recent records (by date) for all unique values in a certain field in the query. I'll be pulling data from 3 different tables as well. Since my description is usually inadequate, here's a simple example:

Before Query:

Date Field
1/1/07 A
1/2/07 A
1/2/07 B
1/2/07 C
1/3/07 A
1/4/07 B

After Query:

Date Field
1/3/07 A
1/4/07 B
1/2/07 C

Does that make sense? Is there a simple solution?
May 10 '07 #1
10 7937
MMcCarthy
14,534 Recognized Expert Moderator MVP
For one table the solution would be

Expand|Select|Wrap|Line Numbers
  1. SELECT Max([Date]), Field FROM TableName
  2. GROUP BY Field
As for joining three table I would need more information. If you can post the actual meta data of the tables as well as details of what you want returned we will try to help.

Here is an example of how to post table MetaData :
Table Name=tblBookings
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. StudentID; Autonumber; PK
  3. Family; String; FK
  4. Name; String
  5. University; String; FK
  6. Mark; Numeric
  7. LastAttendance; Date/Time
May 12 '07 #2
jconstan
12 New Member
hey there,

i was searching for solutions to my problem and came across this discussion. this is the EXACT problem i am having.

I want to pull the most recent date from the "status subform" pulls the project "name" from its main form.

I tried using Max(Date) to get the most recent date, however it only pulls "1/4/07 B" which is the latest of ALL the dates, not just he "B" dates. (from above illustration)

i tried matching it to the main table as well but that isn't working either :S
Any suggestions?
Jun 8 '07 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
hey there,

i was searching for solutions to my problem and came across this discussion. this is the EXACT problem i am having.

I want to pull the most recent date from the "status subform" pulls the project "name" from its main form.

I tried using Max(Date) to get the most recent date, however it only pulls "1/4/07 B" which is the latest of ALL the dates, not just he "B" dates. (from above illustration)

i tried matching it to the main table as well but that isn't working either :S
Any suggestions?
Try using DMax.

=DMax("[Date]","TableName","[name]='" & [Forms]![MainFormName]![name] & "'")
Jun 8 '07 #4
jconstan
12 New Member
Try using DMax.

=DMax("[Date]","TableName","[name]='" & [Forms]![MainFormName]![name] & "'")
hey sorry to be a bother (pure newb and self taught one at that) i used DMax but am getting the msg "enter parameter value"

here are the tables, forms and fields im dealing with

Main form = Status>>>Table = Project Management...Relevant Field = Project Name
Sub form = Status Updates Subform>>>Table = Status Updates Sub...Relevent Field = "Date"

Thanks again for the help
Jun 8 '07 #5
MMcCarthy
14,534 Recognized Expert Moderator MVP
I have to go out for a couple of hours. I'll look at this when I get back if someone hasn't already posted on it.
Jun 8 '07 #6
jconstan
12 New Member
I have to go out for a couple of hours. I'll look at this when I get back if someone hasn't already posted on it.
alright not a problem, thank you!
Jun 8 '07 #7
Leanne123
2 New Member
hey jconstan

i think i am having the same problem

i currently have a sub datasheet in one of my queries, which feeds into a report.

i am wondering how to filter the sub datasheet to show the latest update, which is what i think you are doing as well.

i think if you use a sub datasheet as i did it will save some problems, such as being able to bring up all the updates for a specific record...although then you get my problem which is i can not filter the sub datasheet :S

let me know how its goin
Jun 11 '07 #8
MMcCarthy
14,534 Recognized Expert Moderator MVP
hey sorry to be a bother (pure newb and self taught one at that) i used DMax but am getting the msg "enter parameter value"

here are the tables, forms and fields im dealing with

Main form = Status>>>Table = Project Management...Relevant Field = Project Name
Sub form = Status Updates Subform>>>Table = Status Updates Sub...Relevent Field = "Date"

Thanks again for the help
My apologies, this got lost in the shuffle.

OK, try this (the "Status Updates Sub" table has to have a field [name] which corresponds to the same project name in the main form)


=DMax("[Date]","Status Updates Sub","[name]='" & [Forms]![Status]![Project Name] & "'")
Jun 11 '07 #9
Leanne123
2 New Member
can you query the date within the report instead? maybe that will work?
Jun 11 '07 #10
MMcCarthy
14,534 Recognized Expert Moderator MVP
hey there thanx for the response,

i tried using the code, however it is telling me to enter the parameter value: forms!Status!Project Name!...the form name and field are both correct so i dont know what the problem is :S
As this post is from Leanne, I'm confused?

Why is there an exclamation mark after ProjectName?

If the field ProjectName has a space then it needs to be enclosed in square brackets as follows:

Forms!Status![Project Name]

Edit: As the last post has been edited this doesn't make sense to the thread any more. Please don't play around like this or the experts will get very annoyed and not be inclined to assist you.
Jun 11 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

6
4345
by: Toucan | last post by:
i need to retrieve the most recent timestamped records with unique names (see working query below) what i'm having trouble with is returning the next-most-recent records (records w/ id 1 and 3...
2
2526
by: Willem | last post by:
Hi there, I'm sort of new with doing much record manipulation with queries. Up till now I've been programming VBA and doing record looping to get my results. This works fine but tends to get...
2
7050
by: John | last post by:
I have a query that returns this recordset: Bob, 1/1/2000 Bob, 3/1/2001 Bob, 2/4/2004 Bob, 5/9/2002 I need the query to return this instead: Bob, 2/4/2004 So, it needs to return the most...
4
33644
by: suffrinmick | last post by:
Hi everyone! I (Along with the help of some of you guys!) have managed to get a query working which takes multiple values (types of organisation) from a list box. The query returns a list of...
8
3694
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
3
376
by: c tom | last post by:
id name location 1 tom new york 2 jeny sicago 3 tom new york 4 luca sidney 5 luca sidney i want to make below table using query. id name location
2
1402
by: Mike Curry | last post by:
I have run into a problem, I have 2 fields in my database, both key fields: Table 1 ===== Field X <key> Field Y <key> In field X, there are say about 3 records for each unique Field Y. I...
2
2216
by: Jimmy Stewart | last post by:
Ok, I'm trying to write a query that is starting to wear me down. What I'm trying to do is create a year end report that gets sent to all of my customers who meet two criteria. One they are...
9
3028
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped....
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7070
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.