Solved

SQL Query

Posted on 2013-11-14
3
350 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 119

Accepted Solution

by:
Rey Obrero 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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…

912 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now