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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|