UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Help finding lastest timestamp enter for item    
 
   
countrybound
post Nov 6 2005, 10:02 PM
Post #1

New Member
Posts: 3



I have a table that records a timestamp for each a record in another table is changed and what was changed. I'm trying to build a query that will list out the last thing changed for each record and when it was changed. Any help would be greatly appreciated. Below is a sample table layout.

ID Time Item
1 1/1/2005 1
2 1/2/2005 1
1 1/3/2005 2
2 1/4/2005 2
2 1/5/2005 1

Ned to get query to show
ID Time
1 1/3/2005 2
2 1/5/2005 1
Go to the top of the page
 
+
DougY
post Nov 6 2005, 11:05 PM
Post #2

Utterly Abby-Normal
Posts: 9,754
From: Seattle, WA [USA]



Welcome to Utter Access Forums!

You will need to use a sub query or two queries for that:

First query will identify the latest date per each ID (let's name it qryMx)
Second query will return the additional data about the record with the latest date. The query will join the table with qryMx.

BTW, don't you have a PK for the table? It will make for an easier join for the second query.

If you need help with the queries syntax, we'll go through it.

HTH
Go to the top of the page
 
+
DangerMouse1981
post Nov 7 2005, 07:24 AM
Post #3

UtterAccess Enthusiast
Posts: 96



I'm looking to achieve similar functionality; to identify all records with the lastest date and then run a sub query on those records, I'm very new to access so any help on the query syntax would be great.

Thanks
Go to the top of the page
 
+
countrybound
post Nov 7 2005, 05:26 PM
Post #4

New Member
Posts: 3



Doug,

Thanks for the quick reply. I do need some help on the queries.
How would I identify the latest date per each ID?

Thanks again,
Aaron
Go to the top of the page
 
+
DougY
post Nov 7 2005, 11:09 PM
Post #5

Utterly Abby-Normal
Posts: 9,754
From: Seattle, WA [USA]



Hi Aaron and DangerMouse,

First, you will need to create a summary query (Group by/Totals):

Start a query wizard, add the table you are going to report on (we'll call it MyTable)
Add the following fields: ID, and Time and click on NEXT
Save that query as qryMx
In the design mode:
Click on the TOTALS icon (Sigma = Looks like an edged E)
Change the Group By under the Time field to Max
When you run this query it should return one record per ID with the latest date

Start another query in design view
Add MyTable and qryMx
Click on the ID in MyTable and drag to the ID in qryMx
A line will form between them
Now do the same from Time in MyTable to MaxOfTime in qryMx
Double click on the fields you want to report from MyTable... they will be placed in the query grid (you can also click and drag)

That should do it...

BTW, TIME is a reserved word and you should not use it as an object name.
Go to the top of the page
 
+
mishej
post Nov 8 2005, 12:11 AM
Post #6

Retired Moderator
Posts: 11,289
From: Milwaukee, WI



You need a subquery to identify which records of the sub-group you are interested in. Something like:
CODE
SELECT
  s.*
FROM
  testData1 As s
WHERE
  Format(ID, "000000") & Format(xTime, 'YYYYMMDD') in
  (SELECT TOP 1 Format(ID, "000000") & Format(xTime, 'YYYYMMDD')
   FROM testData1 WHERE ID = s.ID
   ORDER BY Format(ID, "000000") & Format(xTime, 'YYYYMMDD') DESC);
Go to the top of the page
 
+
countrybound
post Nov 9 2005, 08:11 AM
Post #7

New Member
Posts: 3



Thanks - works greart
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 20th May 2013 - 09:47 AM