Solved

SQL Query

Posted on 2013-11-14
3
381 Views
Last Modified: 2013-12-12
Access 2010

Ok I am using Access to get data from 375,000 records.  I know I have 23,000 unique people associated with the records.  columns A,B,C,D are all static information about the person.  I also have a date last seen which I want to use the max date.

How do I use the max of the date to find the latest instance of the complete record.  Every time I try to use the max date and include any column F,G,H, I  it gives me all of the records.

I have searched and I can't quite tie the answers to my data.

I have a unique id column (A),  person ID column (B), and a date last seen column (E), I can't figure out how to get the max date (E) and still include the (A) to let me join to the rest of my data.
0
Comment
Question by:Sean Meyer
3 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39649223
Start with a grouping query:

Select personID, max(datefield) as lastSeen
From yourTable
Group by personID

Save the query.

Create another query joining your people table to that query, linking it on personID and LastSeen.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 350 total points
ID: 39649296
try this single query


select a.*
from TableName as a
inner join
(select b.[person ID],max(b.[date last seen]) as maxdate
      from tableName as b
      group by b.[person ID]) as c
on a.[person ID]=c.[person ID] and a.[date last seen]=c.[maxDate]


.change tableName with the actual name of table and fields accordingly
0
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 150 total points
ID: 39651268
select a.*
from yourtable a,
(select personid, max(date) as maxdt
 from yourtable
 group by personid) as b
where a.personid = b.personid
  and a.date = b.maxdt;
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question