PC Review


Reply
Thread Tools Rate Thread

Query to find the most recent record for each duplicate record

 
 
Microsoft News Server
Guest
Posts: n/a
 
      13th Jun 2008
I am working with a customer database which, unfortunately, contains some
duplicate information. Existing customers were sometimes added as new
customers. I need to create a query which will find only the most recent
record of each group of records which contain the same customer name. Any
help would be appreciated. Here is an example of what I need:



Existing Data

Name Date Other Information

Jane Smith 3/21/2004 Address, Phone, etc.

Jane Smith 7/02/2006 Address, Phone, etc.

Jane Smith 9/27/2007 Address, Phone, etc.

Jane Smith 3/19/2008 Address, Phone, etc.

John Doe 1/21/2006 Address, Phone, etc.

John Doe 3/24/2007 Address, Phone, etc.

John Doe 4/1/2008 Address, Phone, etc.



Desired Query Output

Name Date Other Information

Jane Smith 3/19/2008 Address, Phone, etc.

John Doe 4/1/2008 Address, Phone, etc.


 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      13th Jun 2008
On Fri, 13 Jun 2008 00:29:24 -0400, "Microsoft News Server"
<(E-Mail Removed)> wrote:

>I am working with a customer database which, unfortunately, contains some
>duplicate information. Existing customers were sometimes added as new
>customers. I need to create a query which will find only the most recent
>record of each group of records which contain the same customer name. Any
>help would be appreciated. Here is an example of what I need:
>
>
>
>Existing Data
>
>Name Date Other Information
>
>Jane Smith 3/21/2004 Address, Phone, etc.
>
>Jane Smith 7/02/2006 Address, Phone, etc.
>
>Jane Smith 9/27/2007 Address, Phone, etc.
>
>Jane Smith 3/19/2008 Address, Phone, etc.
>
>John Doe 1/21/2006 Address, Phone, etc.
>
>John Doe 3/24/2007 Address, Phone, etc.
>
>John Doe 4/1/2008 Address, Phone, etc.
>


A Subquery will do this for you:

Select [Name], [Date], [Other information] FROM yourtable
WHERE [Date] =
(SELECT Max([Date] FROM yourtable AS X WHERE X.[Name] = [yourtable].[name])

Of course, it's quite possible that you have two customers with the same name
- I'm John Vinson, and when I was in school there was a Professor John Vinson
in the med school (he got one of my paychecks, alas I never got his). Also I
hope your example is hypothetical; both Name and Date are reserved words and
should not be used as fieldnames.
--

John W. Vinson [MVP]
 
Reply With Quote
 
 
 
 
Eddie Stevens
Guest
Posts: n/a
 
      13th Jun 2008
Thanks for the help, I think I have a general understanding of the query
that you came up with but I am having some trouble with the syntax. Here are
the actual table, query, and field names along with what I typed in for the
query. I am getting a syntax error.



SELECT Customers.ID, Customers.FullName, Customers.SaleDate FROM Customers

WHERE [SaleDate] = (SELECT Max([SaleDate] FROM Customers AS X WHERE
X.[FullName] = [Customers].[FullName]));



Existing Data: Table Name "Customers"

ID FullName SaleDate

12 Jane Smith 3/21/2004

15 Jane Smith 7/02/2006

17 Jane Smith 9/27/2007

25 Jane Smith 3/19/2008

45 John Doe 1/21/2006

79 John Doe 3/24/2007

89 John Doe 4/1/2008



Desired Query Output: Query Name "Current"

ID FullName SaleDate

25 Jane Smith 3/19/2008

89 John Doe 4/1/2008




 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      14th Jun 2008
SELECT Customers.ID, Customers.FullName, Customers.SaleDate
FROM Customers
WHERE [SaleDate] =
(SELECT Max([SaleDate])
FROM Customers AS X
WHERE X.[FullName] = [Customers].[FullName])

Parens are your friend and your traitorous enemy.


'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Eddie Stevens wrote:
> Thanks for the help, I think I have a general understanding of the query
> that you came up with but I am having some trouble with the syntax. Here are
> the actual table, query, and field names along with what I typed in for the
> query. I am getting a syntax error.
>
>
>
> SELECT Customers.ID, Customers.FullName, Customers.SaleDate FROM Customers
>
> WHERE [SaleDate] = (SELECT Max([SaleDate] FROM Customers AS X WHERE
> X.[FullName] = [Customers].[FullName]));
>
>
>
> Existing Data: Table Name "Customers"
>
> ID FullName SaleDate
>
> 12 Jane Smith 3/21/2004
>
> 15 Jane Smith 7/02/2006
>
> 17 Jane Smith 9/27/2007
>
> 25 Jane Smith 3/19/2008
>
> 45 John Doe 1/21/2006
>
> 79 John Doe 3/24/2007
>
> 89 John Doe 4/1/2008
>
>
>
> Desired Query Output: Query Name "Current"
>
> ID FullName SaleDate
>
> 25 Jane Smith 3/19/2008
>
> 89 John Doe 4/1/2008
>
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find the most recent record of each payee by date. A.S. Microsoft Access Queries 16 6th Apr 2009 07:36 PM
Showing most recent record for each employee in a query CEV Microsoft Access Queries 2 30th May 2006 10:15 PM
Sum of Most Recent to Most Recent-12 months =?Utf-8?B?T2NlbGxOdXJp?= Microsoft Access Queries 5 4th Jan 2006 03:51 PM
Showing the most recent record for each client jeff klein Microsoft Access Queries 8 13th Jul 2004 04:08 AM
Find most recent assignment for each employee Rick Microsoft Access Queries 2 25th Mar 2004 04:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:12 PM.