Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 16th, 2004, 08:45 AM
Registered User
 
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Selecting the Latest Records

Hi

One of my tables contains a list of documents IDs their revision and the date issued.

From this table i'm trying to select the latest revision of the document.

The table has as a primary key made fron the Document ID and Revision columns.

I am using Access 2002



 
Old September 16th, 2004, 11:22 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

Is the date issued your latest document date? or if is any other date like create date you can use distinct and max

Here is an example using the customers and orders table in Northwind Database

SELECT DISTINCT Customers.CustomerID, Customers.CompanyName, Customers.City, Customers.Country, Max(Orders.OrderDate) AS MaxOfOrderDate
FROM Customers RIGHT JOIN Orders ON Customers.CustomerID = Orders.CustomerID
GROUP BY Customers.CustomerID, Customers.CompanyName, Customers.City, Customers.Country
HAVING (((Max(Orders.OrderDate)) Between #1/1/1997# And #12/31/1997#));
 
Old September 16th, 2004, 05:09 PM
Registered User
 
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Jemacc

The date is not unique to the record but it is always later than the earlier revisions.

I tried your Select Statement transposing my Table and field names but it selected all the recors in the table.


To make my problem a bit clearer here is sample data

Document Revision Table
DocID Rev Date
Dwg1 A 9/1/2004
Dwg1 B 9/5/2004
Dwg3 C 9/15/2004
dwg4 A 9/1/2004
dwg4 C 9/15/2004

Required result from Query

DocID Rev Date
Dwg1 B 9/5/2004
Dwg3 C 9/15/2004
dwg4 C 9/15/2004



 
Old September 16th, 2004, 07:21 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

Try this
N=numbers of records

SELECT TOP N DocID,Rev, Date
FROM Revision_Table
GROUP BY DocID,Rev, Date
ORDER BY DocID,Rev, Date desc






Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting records in a query firefighter2045 Access VBA 5 August 28th, 2008 08:14 AM
Selecting one of possibly many related records rodmcleay SQL Server 2000 2 March 24th, 2007 12:49 AM
selecting records from excel androoo Pro VB 6 1 January 12th, 2005 12:18 PM
selecting records from multiple tables cygnusx04 Classic ASP Databases 1 October 28th, 2004 05:36 AM
Returning ONLY the latest records in a query kilkerr1 Access 3 November 3rd, 2003 01:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.