DaveTappenden
Programmer
- Jan 16, 2002
- 21
- 0
- 0
Please help, I have a severe case of brain fade!.
I am trying to create a query based on 2 tables using an inner join, but only selecting the record in the 2nd table with the highest value (Invoice Number).
The following query will give me all Invoices for a customer:
SELECT Cust.CustName, Inv.InvNr
FROM Cust INNER JOIN Inv ON Cust.CustID = Inv.CustID
WHERE (((Cust.CustName)="Smith");
- but I only want to extract a single row from the 2nd table, which is the last (highest) invoice number.
So, I add the Max aggregate function:
SELECT Cust.CustName, MAX(Inv.InvNr)
FROM Cust INNER JOIN Inv ON Cust.CustID = Inv.CustID
WHERE (((Cust.Name)="Smith");
However, this causes the query to fail with an Access error "You have tried to execute a query that does not include the specified expression 'CustName' as part of an aggregate function"
Can any kind person explain what I am doing wrong please?
Thanks.
David
I am trying to create a query based on 2 tables using an inner join, but only selecting the record in the 2nd table with the highest value (Invoice Number).
The following query will give me all Invoices for a customer:
SELECT Cust.CustName, Inv.InvNr
FROM Cust INNER JOIN Inv ON Cust.CustID = Inv.CustID
WHERE (((Cust.CustName)="Smith");
- but I only want to extract a single row from the 2nd table, which is the last (highest) invoice number.
So, I add the Max aggregate function:
SELECT Cust.CustName, MAX(Inv.InvNr)
FROM Cust INNER JOIN Inv ON Cust.CustID = Inv.CustID
WHERE (((Cust.Name)="Smith");
However, this causes the query to fail with an Access error "You have tried to execute a query that does not include the specified expression 'CustName' as part of an aggregate function"
Can any kind person explain what I am doing wrong please?
Thanks.
David