Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 16th, 2004, 08:45 AM
Registered User
 
Join Date: Sep 2004
Location: Harthill, , United Kingdom.
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



Reply With Quote
  #2 (permalink)  
Old September 16th, 2004, 11:22 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: Lehigh Acres, FL, USA.
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#));
Reply With Quote
  #3 (permalink)  
Old September 16th, 2004, 05:09 PM
Registered User
 
Join Date: Sep 2004
Location: Harthill, , United Kingdom.
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



Reply With Quote
  #4 (permalink)  
Old September 16th, 2004, 07:21 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: Lehigh Acres, FL, USA.
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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:05 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.