jdepinet
Jan 4 2011, 06:50 PM
This seems easy but I'm lost.....I have tblAddress the contains:
pkAddress
fkOwner
ingNumber
strStreet
strCity
ingZip
dtDateEntered
The user can add as many addresses as needed per owner and everytime a new address is added it is time stamped. I want a query show just the most current address for each owner. Any Help? Thanks John
Alan_G
Jan 4 2011, 07:00 PM
Hi
Create a new query using the Query Designer. Add the tables and the fields from them into the query design grid, then turn the query into a Totals query, when you'll see a new row added to the design grid. Select Max from the drop down in the dtDateEntered field and try running the query
Doug Steele
Jan 4 2011, 07:01 PM
SELECT pkAddress, fkOwner, ingNumber, strStreet, strCity, ingZip, dtDateEntered
FROM tblAddress INNER JOIN
(SELECT pkAddress, Max(dtDateEntered) As LatestEntry
FROM tblAddress
GROUP BY pkAddress) AS Subq
ON tblAddress.pkAddress = Subq.pkAddress
AND tblAddress.dtDateEntered = Subq.LatestEntry
ORDER BY pkAddress
jdepinet
Jan 4 2011, 07:04 PM
Still returns all of the addresses
jdepinet
Jan 4 2011, 07:20 PM
Doug, still showing all records. I only want to show the newest entries by Owner. Any more suggestions? John
Doug Steele
Jan 4 2011, 07:32 PM
Something's wrong with the data then.
Try this. Run the following query:
SELECT pkAddress, Max(dtDateEntered) As LatestEntry
FROM tblAddress
GROUP BY pkAddress
Do you get only one row for each value of pkAddress?
Assuming you do only get one row for each value of pkAddress, look closely at the results of the original query. Do each of the duplicate rows have the same value for dtDateEntered?
RickA
Jan 4 2011, 07:32 PM
Try this:
SELECT pkAddress, fkOwner, ingNumber, strStreet, strCity, ingZip, Subq.LatestEntry
FROM tblAddress
INNER JOIN
(SELECT fkOwner, Max(dtDateEntered) As LatestEntry
FROM tblAddress
GROUP BY fkOwner) As Subq
ON tblAddress.fkOwner= Subq.fkOwner
AND tblAddress.dtDateEntered = Subq.LatestEntry
Doug Steele
Jan 4 2011, 07:36 PM
Good catch, Rick. I misinterpretted the fields in the table: your approach would appear to be correct.
Sorry about that, jdepinet.
jdepinet
Jan 4 2011, 07:53 PM
It works perfect! Thanks Doug and Rick. John
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.