A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Query with most recent contract



 
 
Thread Tools Display Modes
  #1  
Old December 28th, 2006, 12:21 AM posted to microsoft.public.access.queries
sarah
external usenet poster
 
Posts: 633
Default Query with most recent contract

I could use some help. I have a table with customer info and a table with
contracts. They are linked by an ID field. I would like to create a query
that only links the most recent contract (it is determined by a date field)
for the customer. I know this sounds simple but I can't think of how to do
it. Thanks for your help.

Sarah
  #2  
Old December 28th, 2006, 12:57 AM posted to microsoft.public.access.queries
Marshall Barton
external usenet poster
 
Posts: 5,361
Default Query with most recent contract

Sarah wrote:

I could use some help. I have a table with customer info and a table with
contracts. They are linked by an ID field. I would like to create a query
that only links the most recent contract (it is determined by a date field)
for the customer. I know this sounds simple but I can't think of how to do
it.


I think this will do that:

SELECT Customers.*, Contracts.*
FROM Customers INNER JOIN Contracts
ON Customers.ID = Contracts.customerID
WHERE Contracts.contractdate = (
SELECT Max(X.contractdate)
FROM Contracts As X
WHERE X.customerID = Contracts.customerID
)

--
Marsh
MVP [MS Access]
  #3  
Old December 28th, 2006, 06:16 AM posted to microsoft.public.access.queries
sarah
external usenet poster
 
Posts: 633
Default Query with most recent contract

Thanks Marshall - it worked perfectly!

"Marshall Barton" wrote:

Sarah wrote:

I could use some help. I have a table with customer info and a table with
contracts. They are linked by an ID field. I would like to create a query
that only links the most recent contract (it is determined by a date field)
for the customer. I know this sounds simple but I can't think of how to do
it.


I think this will do that:

SELECT Customers.*, Contracts.*
FROM Customers INNER JOIN Contracts
ON Customers.ID = Contracts.customerID
WHERE Contracts.contractdate = (
SELECT Max(X.contractdate)
FROM Contracts As X
WHERE X.customerID = Contracts.customerID
)

--
Marsh
MVP [MS Access]

 




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:41 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.